Fire only one Custom Validator at a time

Posted by Lijo on Stack Overflow See other posts from Stack Overflow or by Lijo
Published on 2012-12-19T16:50:44Z Indexed on 2012/12/19 17:03 UTC
Read the original article Hit count: 248

Filed under:
|

I have two Custom Validators attached to a textbox. The textbox is to enter comma separated list of emails. The first validator checks that there is not duplicate email address. The second custom validator checks that all the email addresses are in valid format. I have following code and it works fine.

However, when both the failure criteria is met both of them are firing and I get two * at the right side of my textbox. What is the best approach to show only one * at a time?

enter image description here

CODE

<asp:CustomValidator ID="valEmailRecipients" runat="server" ControlToValidate="txtEmailRecipients"
ClientValidationFunction="isUniqueElements" OnServerValidate="IsUniqueEmail_Validate"
Text="*" ErrorMessage="There should be no duplicate email address for a report"
ValidationGroup="Save">
</asp:CustomValidator>

<asp:CustomValidator ID="valEmailFormat" runat="server" ControlToValidate="txtEmailRecipients"
ClientValidationFunction="checkEmailFormat" OnServerValidate="IsValidEmailFormat_Validate"
Text="*" ErrorMessage="Entries should be valid email addresses separated by comma"
ValidationGroup="Save">
</asp:CustomValidator>

REFERENCES:

  1. Validating with a Custom Function for ASP.NET Server Controls

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET