Duplicate Validators


If I have more than one asp.net server validator on the same control,
(Suppose both of them can return false in a specific situation), and I want to display only one message (except for the check summary),
How can I achieve this goal and group the Text property of all validators that reference the same control?

If I implement this situation, I get the Text attribute of each of the validators as an output ...

+6
source share
2 answers

Put these two validator controls in a separate ValidationGroup and create a new custom validator that validates these two validator controls with a unified message.

 protected void CustomValidator (object sender, ServerValidateEventArgs e) { e.IsValid = validator1.IsValid && validator2.IsValid } 
+6
source

You can get it using javascript function and put it in CustomeValidator and set text message in customeValidator

 function ValidateTwoValidations(oSrc, args) { var Val1 = document.getElementById("Validator1ClientId"); var Val2 = document.getElementById("Validator2ClientId"); if (Val1.IsValid = false && Val2.IsValid = false){ args.IsValid = false; } else { args.IsValid = true; } } 
0
source

Source: https://habr.com/ru/post/886702/


All Articles