3

我有这个文本框和提交按钮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 访问主页,它可以工作。

这是网站http://www.quotestample.com

4

1 回答 1

2

查看您的网站并尝试使用上面发布的代码重新生成那里发生的事情后,您似乎没有在搜索按钮上放置 OnClick 事件。因此,当单击按钮时,它只是在不通过代码的情况下进行回发,因此不会触发任何事件。

尝试将OnClick="btnSearch_Click"添加到按钮。

<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click"/>
于 2013-02-07T09:16:07.737 回答