Adding custom error message to ValidationSummary without validators
Validators are a great thing in the ASP.Net world (as well as the .Net WinForms world...), but sometimes they don't suffice. For example, if you want to validate something not related to a control on the page or something very complex you can't achieve even with the custom validators, you may want a particular solution like this one.
First approach : using the CustomValidator
With this approach you simply have to do the following piece of code when you want to add a custom message to your validator :
CustomValidator val = new CustomValidator();
val.IsValid = false;
val.ErrorMessage = "Custom error message to add to the ValidationSummary";
This is a cool, clean and simple way to add custom error messages to the ValidationSummary.
Second approach : creating a validator by implementing IValidator
The .Net framework allows you to create very custom validator by implementing the IValidator interface. So you create the validator and then use the same technique I've just showed you before, just like this :
ValidationError : IValidator
.ErrorMessage = message;
} public void
.IsValid = false
ValidationError("Your custom error message"
Personnaly I prefer this one because you are completely custom and you can add messages in a single line of code.