【问题标题】:Submit button conflicts with to different functions提交按钮与不同功能的冲突
【发布时间】:2012-03-16 00:05:22
【问题描述】:

朋友们,我遇到了一个奇怪的问题,我需要你的建议来解决它。

在我的母版页中,我使用了一个带有按钮的搜索框,它在所有页面中都可以正常工作,除了“请求报价页面”,它有一个供用户填写的表格。 如果一个人在 Request Quote 页面上并想使用 head 部分的搜索框进行搜索,它不会将用户带到搜索结果页面,而是触发“RequestQuote Form”的表单验证

这是我的代码; MasterPage Head 部分的搜索框

<asp:TextBox ID="SearchBox" runat="server" CssClass="search_textbox" ></asp:TextBox>
<asp:ImageButton ID="SearchButton" runat="server" onclick="SearchButton_Click" />

protected void ISearchButton_Click(object sender, ImageClickEventArgs e)
{ Response.Redirect("Search-commercial.aspx?Zip=" + SearchBox.Text); }

来自请求报价页面的一些代码

<asp:TextBox ID="Email" runat="server"></asp:TextBox>
<asp:ImageButton ID="QuoteButton" runat="server" onclick="QuoteButton_Click" />

protected void IQuoteButton_Click(object sender, ImageClickEventArgs e)
{ SqlDataSource3.Insert();
  Response.Redirect("InstallerThanks.aspx");        
}

朋友知道我哪里出错了吗?

【问题讨论】:

  • 这是什么意思:“它进入第一个文本框字段”?如果用户点击SearchButton 处理程序IQuoteButton_Click 将被调用而不是ISearchButton_Click?或者你的意思是按下回车键?
  • 发布呈现的 html 的相关位可能会有所帮助。对我来说,您的控件中的 id 或名称似乎有冲突。
  • 当一个人点击搜索按钮时,它不会进入搜索结果页面,而是触发请求报价表单的验证。
  • 好吧,我幸运地找到了解决方案,我默认禁用所有表单验证器,除非用户单击提交报价按钮,因为所有验证器都被禁用,所以我的搜索框按钮没有冲突,希望这个解决方案可以帮助其他有同样问题的人
  • @AliKhan:你应该使用ValidationGroups 来避免这个问题。

标签: c# asp.net forms button


【解决方案1】:

您应该使用不同的ValidationGroups,而不是禁用所有验证器。

【讨论】:

    猜你喜欢
    • 2014-07-11
    • 2012-06-16
    • 2019-06-22
    • 2015-01-19
    • 2015-05-12
    • 1970-01-01
    • 2017-09-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多