There are time where you need to display a message to the users. Here’s how to do it with a Validation Summary on your ASP.NET page.
I use this when I want to display an error message that doesn’t come from an exception or another validation.
This is helpful when you want all messages to have the same look and feel.
You MUST have a validation summary on your page otherwise nothing happens.
Below is the code.
CustomValidator val = new CustomValidator(); val.IsValid = false; val.ErrorMessage = "My error message for the ValidationSummary"; this.Page.Validators.Add(val);
You create create a custom validator, set it to invalid, define the error message, and add it to your page.