【问题标题】:how to bypass required field validation when clicking the cancel button?单击取消按钮时如何绕过必填字段验证?
【发布时间】:2015-01-16 08:59:37
【问题描述】:

我为我的文本框使用了 HTML 输入类型来利用所需的属性。现在我的困境是如果不填写具有必需属性的字段,我就无法离开页面。我尝试使用将 causeValidation 设置为 false 但它不起作用。我不能将我的文本框更改为 asp 文本框,因为这将是页面中的一个很大的变化。还有其他方法吗?

<asp:Button runat="server" ID="buttonCancel" CssClass="cu-btn-direction" style="float:right; margin-right: 15px; margin-bottom: 60px;" Text="Cancel" CausesValidation="false" />

编辑:

我尝试添加验证组,但没有奏效...有效的方法是将 UseSubmitBehavior 设置为 false http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.usesubmitbehavior%28v=vs.110%29.aspx,但如链接中所述,如果不启用 js,它将无法工作。还有什么办法吗?

【问题讨论】:

  • 发现这个链接对我有用... stackoverflow.com/questions/18202784/…> 无论有没有js都可以...

标签: html vb.net cancel-button required-field


【解决方案1】:

使用 formnovalidate

<input type="submit" value="Cancel" formnovalidate>

这会绕过所有表单验证,例如 必需

【讨论】:

  • 或者只是改变输入的类型&lt;input type="button" value="Cancel"&gt;
猜你喜欢
  • 2011-09-06
  • 2013-08-11
  • 1970-01-01
  • 2023-03-09
  • 1970-01-01
  • 2016-04-03
  • 2017-08-14
  • 2022-10-24
  • 2020-09-02
相关资源
最近更新 更多