【问题标题】:ASP.NET MasterPage Postback not working from homepageASP.NET MasterPage 回发无法从主页工作
【发布时间】:2013-02-07 17:16:07
【问题描述】:

我在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.quotestemple.com

【问题讨论】:

  • 能否请您也在这里放置母版页占位符,输入代码。
  • 我不同意你的最后一句话......即使在域的根目录中使用“default.aspx”,它也对我不起作用
  • 能否请您也发布您的 btnSearch html。
  • btnsearch 代码不相关,因为回发不执行母版页重定向。所以它没有到达那里。
  • Aristos@什么输入码?

标签: asp.net master-pages postback


【解决方案1】:

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

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

<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click"/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-30
    相关资源
    最近更新 更多