简体   繁体   English

ASP.NET Webforms - ValidationSummary 显示不同的错误

[英]ASP.NET Webforms - ValidationSummary show distinct errors

When I am using ValidationSummary to validate my page if I have duplicate errors my validation will show all this errors.当我使用 ValidationSummary 验证我的页面时,如果我有重复的错误,我的验证将显示所有这些错误。 I want to display a distinct list of errors.我想显示一个不同的错误列表。 I think that the best approach is to ovverride an event.我认为最好的方法是覆盖事件。 But I don't know what event to override.但我不知道要覆盖什么事件。 What is the event that deals with showing errors.处理显示错误的事件是什么。

I don't want solutions for MVC projects!我不想要 MVC 项目的解决方案!

ValidationSummary collect all the error in your input and display. ValidationSummary 收集输入和显示中的所有错误。 So indirectly you have answerd your question by yourself in your question You just don't know the syntax i think.Here it is:所以间接地,你在你的问题中自己回答了你的问题,你只是不知道我认为的语法。这里是:

If you have some collection of input in aspx,you have defined also the regular expression for specific input.For example:如果您在 aspx 中有一些输入集合,则您还​​为特定输入定义了正则表达式。例如:

 <div>
             <asp:TextBox ID="txt" runat="server" MaxLength="100"></asp:TextBox>
           <asp:RegularExpressionValidator ID="revtxt" runat="server"SetFocusOnError="true"ErrorMessage="Please enter correct txt" ControlToValidate="txt" ValidationGroup="Submit"
        ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
    <div>
    <div>
             <asp:TextBox ID="txt1" runat="server" MaxLength="100"></asp:TextBox>
           <asp:RegularExpressionValidator ID="revtxt1" runat="server"SetFocusOnError="true"ErrorMessage="Please enter correct txt1" ControlToValidate="txtEmail" ValidationGroup="Submit"
        ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
    <div>
<div>
 <asp:Button ID="btnSubmit" runat="server" Text="Save" ValidationGroup="Submit" OnClick="btnSubmit_Click" />
</div>
<div>
<asp:ValidationSummary ID="ValidationSummary"runat="server"ValidationGroup="Submit" />
</div>

So in every input or button you have to define ValidationGroup attribute Else if you want to check in codebehind if all of this input are validated you have to do this:因此,在每个输入或按钮中,您必须定义ValidationGroup属性 Else 如果要检查代码隐藏(如果所有这些输入都已验证),则必须执行以下操作:

if(Page.IsValid)
{
//your code here
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM