ASP.NET MasterPage 回发无法从主页运行

标签 asp.net master-pages postback

我在 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

最佳答案

查看您的网站并尝试使用上面发布的代码重新生成那里发生的情况后,您似乎没有在搜索按钮上放置 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/

相关文章:

asp.net - 如何使用 Entity Framework 代码优先实现在迁移时更新每一行的唯一值

asp.net - 如何在 IIS 中禁用或删除 DirectoryListingModule 以防止 HTTP 405 错误

javascript - 如何在 SharePoint 2013 Online 中使用 JavaScript 动态创建母版页文件?

c# - MasterPage 中的 ValidationSummary 隐藏成功标签

javascript - 刷新页面,不重新发送 POST 数据(ASP.NET)

php - 我怎样才能从 angularJS 到 phalcon php 发出完整的回发请求

c# - 用户 'IIS APPPOOL\myAppPoolName' 登录失败,无法为此添加新用户

asp.net - IIS7环境下Application_Start异常处理

c# - Nullref Exc。在智能感知检测到的标签上?

asp.net - 更新面板内的用户控制导致整页回发