Reputation: 385
If I have more than one asp.net server validator on the same control,
(Suppose that both of them can return false in a specific situation) and I want to display only one message (Except the validation summary),
How can I Achieve this goal and group the Text
property of all the validators that link to the same control?
If I Implement this situation I receive in the output the Text
attribute of each one of the validators...
Upvotes: 5
Views: 302
Reputation: 3297
You can obtain it with javascript function and put it in CustomeValidator & set the Text msg 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;
}
}
Upvotes: 0
Reputation: 23861
Put these two validators control in seperated ValidationGroup
and create a new Custom Validator that checks these two validators controls with unified message.
protected void CustomValidator (object sender, ServerValidateEventArgs e)
{
e.IsValid = validator1.IsValid && validator2.IsValid
}
Upvotes: 6