Fire only one Custom Validator at a time
- by Lijo
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?
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:
Validating with a Custom Function for ASP.NET Server Controls