The problem

This is a really annoying “feature” in ASP.NET 2.0 which thankfully has a simple solution. The problem is that a ValidationSummary control won’t show error messages from CustomValidators on the page. All other validators display as they should in the validationsummary, but not the custom validators.

A solution

Ensure that you set the CustomValidator’s ErrorMessage property. Other controls will display fine in the validation summary if only their Text property is set, but the in the case of the CustomValidator you have to set the ErrorMessage property. IMHO all validation controls should only have an ErrorMessage property and not the misleading Text property, but that of course is another matter entirely.

For some reason I can’t seem to set the ErrorMessage properties using resourcekey attributes in aspx/ascx files only, I don’t know why this is. So in the case of CustomValidators I set their ErrorMessage properties in code, eg in Page_Load.

Other comments

I’m assuming the validationsummary is ShowSummary=”true” and DisplayMode=”list”. Using validationgroups is ok if necessary but not mandatory.

Advertisements