Reputation: 34800
How can I override the error message displayed by the ValidationSummary control in an ASP.NET web forms project?
Rather than displaying an error for each invalid control within the validation group, I want to display a single message e.g. "Invalid form".
Upvotes: 0
Views: 1913
Reputation: 2028
Instead of using asp validation, you can do the validation in the code behind, If the conditions for filling out the form are not met, you can put your error message in a blank label like so
lblErrorMessage.Text = "<span style='color:red;'>Invalid form</span>"
Upvotes: 1
Reputation: 1017
You can try setting ValidationSummary.HeaderText (and clearing the error messages for each validatior), or just create a new CustomValidator when validation fails.
private void DisplayCustomMessageInValidationSummary(string message)
{
CustomValidator CustomValidatorCtrl = new CustomValidator();
CustomValidatorCtrl.IsValid = false;
CustomValidatorCtrl.ErrorMessage = message;
this.Page.Controls.Add(CustomValidatorCtrl);
}
Upvotes: 1