[英]ASP.Net form validation - bypass client side only on button click
I have a form with a bunch of fields that I am using RequiredFieldValidator, RegularExpressionValidator, and CustomValidator. 我有一个带有一堆字段的表单,正在使用RequiredFieldValidator,RegularExpressionValidator和CustomValidator。
I want my form to perform client side checks when tabbing between fields (it currently does this), but I want to force a server side submit when the asp:button is clicked. 我希望表单在字段之间进行制表时执行客户端检查(它当前正在执行此操作),但是我想在单击asp:button时强制服务器端提交。 Right now, if a form field is determined invalid on the client side, the submit button doesn't do anything.
现在,如果确定表单字段在客户端无效,那么提交按钮将不执行任何操作。 I want it to submit the page and perform the server side check.
我希望它提交页面并执行服务器端检查。
The reason I want this to happen is because I want the page to go back to the top and display all possible issues and make it obvious to the user that there was a problem. 我希望发生这种情况的原因是,我希望页面返回顶部并显示所有可能的问题,并使用户清楚地知道存在问题。 Currently if they didn't see the client side error message, they may just click submit, see nothing happen, and end up confused.
当前,如果他们没有看到客户端错误消息,则可以单击“提交”,什么也看不见,最后感到困惑。
Example field on aspx Page: aspx页面上的示例字段:
<asp:TextBox MaxLength="30" ID="LNom" runat="server" /><asp:RequiredFieldValidator ID="reqLNom" runat="server" ErrorMessage="Last Name Required" ControlToValidate="LNom" /><asp:CustomValidator ID="valLNom" runat="server" ErrorMessage="Please enter a valid last name (less than 30 characters in length)." ControlToValidate="LNom" OnServerValidate="ValidationLastName" />
<asp:Button ID="Submit" Text="Submit" runat="server" onclick="Submit_Click" />
Submit button Code Behind: 提交按钮背后的代码:
protected void Submit_Click(object sender, EventArgs e)
{
Page.Validate();
if (Page.IsValid)
{
// Do stuff
}
}
Obviously there is a bit more to this, but you get the idea. 显然,这还有很多,但是您明白了。
Try asp.net ValidationSummary
. 尝试asp.net
ValidationSummary
。 See http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.validationsummary(v=vs.110).aspx It does exactly how you want it. 请参阅http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.validationsummary(v=vs.110).aspx它确实满足您的要求。 It can be a pop up or inline notification that tells the user what s/he needs to fix.
它可以是弹出式通知或内联通知,告诉用户他/他需要修复的问题。
If you add 'CausesValidation="False"' to your asp:button declaration. 如果将“ CausesValidation =” False“”添加到asp:button声明中。 This will cause the postback to happen regardless of the outcome of client side validation
无论客户端验证的结果如何,都会导致发生回发
You can do this client side, no need for a post back. 您可以在客户端进行此操作,无需回发邮件。 Look into the ValidationSummary control:
查看ValidationSummary控件:
http://www.w3schools.com/aspnet/control_validationsummary.asp http://www.w3schools.com/aspnet/control_validationsummary.asp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.