0

How to use a ValidationSummary to display server errors?

Posted January 13th, 2010 in .NET, ASP.NET, Tips and Tricks by Sam Beauvois

Imagine you want to use your ValidationSummary to display server errors as client error, there is a simple way to do that.

First, declare your ValidationSummary, and a CustomValidator with Display property set to “None”


<asp:CustomValidator ID="ServerErrorCustomValidator"
Display="None" runat="server" ValidationGroup="MyValidationGroup" />

<asp:ValidationSummary ID="AdministrationTaskValidationSummary" runat="server" ValidationGroup="MyValidationGroup"/>

Next, in your application code, when an error occurs : set the CustomValidator’s ErrorMessage and IsValid properties :


ServerErrorCustomValidator.ErrorMessage = "Server error :  error description";
ServerErrorCustomValidator.IsValid = false;

Leave a Reply