Jon's Blog

.NET Development & More

ASP.NET: Add New Error Message to Validation Summary Control

You can use this method to add a new error to an existing validation summary control from your code-behind page.  Don't forget to use the proper ValidationGroup that your validation summary is using.

protected void AddErrorToValidationSummary(string errorMessage)
CustomValidator custVal = new CustomValidator();
custVal.IsValid = false;
custVal.ErrorMessage = errorMessage;
custVal.EnableClientScript = false;
custVal.Display = ValidatorDisplay.None;
custVal.ValidationGroup = "MyValidationGroup";