The ValidationSummary Server Control in asp.net


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>
    &nbsp;
   <asp:RequiredFieldValidator ID="RequiredFieldValidator1"
    Runat="server" ErrorMessage="You must enter your first name"
    ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
</p>
<p>Last name
   <asp:TextBox ID="TextBox2" Runat="server"></asp:TextBox>
    &nbsp;
   <asp:RequiredFieldValidator ID="RequiredFieldValidator2"
    Runat="server" ErrorMessage="You must enter your last name"
    ControlToValidate="TextBox2"></asp:RequiredFieldValidator>
</p>
<p>
   <asp:Button ID="Button1" OnClick="Button1_Click" Runat="server"
    Text="Submit"></asp:Button>
</p>
<p>
   <asp:ValidationSummary ID="ValidationSummary1" Runat="server"
    HeaderText="You received the following errors:">
   </asp:ValidationSummary>
</p>
<p>
   <asp:Label ID="Label1" Runat="server"></asp:Label>
</p>

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">
        </asp:RequiredFieldValidator>

Other Related Posts:

Validations:

ASP.NET Validation Server Controls

The RequiredFieldValidator Server Control in asp.net

Validating Drop-Down Lists with the RequiredFieldValidator Control

The CompareValidator Server Control in asp.net

The RangeValidator Server Control in asp.net

The RegularExpressionValidator Server Control in asp.net

The CustomValidator Server Control in asp.net

The ValidationSummary Server Control in asp.net

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s