-1

When I am using ValidationSummary to validate my page if I have duplicate errors my validation will show all this errors. 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!

POIR
  • 3,110
  • 9
  • 32
  • 48
  • 1
    You're going to have to show more to get a better answer but... In my opinion each validator should have a distinct error message. If that is true then even if every validator fails, you will not have any "duplicate" errors. I can't think of a reason to show the same error message for multiple issues unless you're trying to be cryptic. – Daniel Mar 09 '16 at 13:54

1 Answers1

1

ValidationSummary collect all the error in your input and display. 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:

 <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:

if(Page.IsValid)
{
//your code here
}
Fation Hadri
  • 160
  • 2
  • 2
  • 20