The ValidationSummary Server Control in

The ValidationSummary Server Control:

The ValidationSummary control is not a control that performs validations on the content input into your Web forms. Instead, this control is the reporting control, which is used by the other validation controls on a page. You can use this validation control to consolidate error reporting for all the validation errors that occur on a page instead of leaving this up to each and every individual validation control.

A partial page example of the ValidationSummary control

        <p>First name
   <asp:TextBox ID="TextBox1" Runat="server"></asp:TextBox>
   <asp:RequiredFieldValidator ID="RequiredFieldValidator1"
    Runat="server" ErrorMessage="You must enter your first name"
<p>Last name
   <asp:TextBox ID="TextBox2" Runat="server"></asp:TextBox>
   <asp:RequiredFieldValidator ID="RequiredFieldValidator2"
    Runat="server" ErrorMessage="You must enter your last name"
   <asp:Button ID="Button1" OnClick="Button1_Click" Runat="server"
   <asp:ValidationSummary ID="ValidationSummary1" Runat="server"
    HeaderText="You received the following errors:">
   <asp:Label ID="Label1" Runat="server"></asp:Label>

In addition to bulleted lists, you can use the DisplayMode property of the ValidationSummary control to change the display of the results to other types of formats. This control has the following possible values:

  • BulletList
  • List
  • SingleParagraph

You can also utilize a dialog box instead of displaying the results to the Web page.

 Using a dialog box to report validation errors

<asp:ValidationSummary ID="ValidationSummary1" Runat="server"
        ShowMessageBox="True" ShowSummary="False"></asp:ValidationSummary>

Using Images and Sounds for Error Notifications:

An interesting tip regarding the validation controls is that you are not limited to just text — you can also use images and sounds for error notifications.

To do this, you use the ErrorMessage property of any of the validation controls. To use an image for the error, you can simply place some appropriate HTML as the value of this property.

Using images for error notifications

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" Runat="server" ErrorMessage='<img src="error.gif">' ControlToValidate="TextBox1">

Other Related Posts:


ASP.NET Validation Server Controls

The RequiredFieldValidator Server Control in

Validating Drop-Down Lists with the RequiredFieldValidator Control

The CompareValidator Server Control in

The RangeValidator Server Control in

The RegularExpressionValidator Server Control in

The CustomValidator Server Control in

The ValidationSummary Server Control in

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s