我在 MasterPage
中有此文本框和提交按钮
<telerik:RadTextBox ID="txtsearch" runat="server" EnableViewState="false" Height="23px" Width="150px"></telerik:RadTextBox>
<asp:RadioButtonList ID="searchType" runat="server" EnableViewState="False" RepeatDirection="Horizontal" RepeatLayout="Table" Width="160px">
<asp:ListItem Selected="True" Value="1">Authors</asp:ListItem>
<asp:ListItem Value="2">Quotes</asp:ListItem>
</asp:RadioButtonList>
这是 MasterPage
中的代码,当用户单击搜索按钮时执行
protected void btnSearch_Click(object sender, EventArgs e)
{
if (searchType.SelectedValue == "1")
{
Response.Redirect("~/quotes/authors/search/" + HttpUtility.HtmlEncode(txtsearch.Text)+"/1");
}
else
{
Response.Redirect("~/quotes/search/"+ HttpUtility.HtmlEncode(txtsearch.Text)+"/1");
}
}
它可以在除主页之外的任何页面上使用。如果您使用/Default.aspx 访问主页,它就可以工作。
最佳答案
查看您的网站并尝试使用上面发布的代码重新生成那里发生的情况后,您似乎没有在搜索按钮上放置 OnClick 事件。因此,当单击按钮时,它只是执行回发而不执行代码,因此不会触发任何事件。
尝试将 OnClick="btnSearch_Click" 添加到按钮。
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click"/>
关于ASP.NET MasterPage 回发无法从主页运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14731385/