HOME

ASP.NET Tutorial
ASP.NET HOME
ASP.NET Intro
ASP.NET vs ASP
ASP.NET Install
ASP.NET Pages
ASP.NET Controls
ASP.NET Events

References
HTML Controls
Web Controls
Validation Controls
Download XMLSpy here
Please visit our sponsors !

ValidationSummary Control

Back

Definition and Usage

The ValidationSummary control is used to display a summary of all validation errors occurred in a Web page.

The error message displayed in this control is specified by the ErrorMessage property of each validation control. If the ErrorMessage property of the validation control is not set, no error message is displayed for that validation control.


Properties

Property Description
DisplayMode How to display the summary. Legal values are:
  • BulletList
  • List
  • SingleParagraph
EnableClientScript A Boolean value that specifies whether client-side validation is enabled or not
Enabled A Boolean value that specifies whether the validation control is enabled or not
ForeColor The fore color of the control
HeaderText A header in the ValidationSummary control
id A unique id for the control
runat Specifies that the control is a server control.  Must be set to "server"
ShowMessageBox A Boolean value that specifies whether the summary should be displayed in a message box or not
ShowSummary A Boolean value that specifies whether the ValidationSummary control should be displayed or hidden

Example 1

In the following example we use the ValidationSummary control to write a bulleted list of fields that are required but left empty by the user:

<html>
<body>
<form runat="server">
<table>
  <tr>
    <td>
    <table bgcolor="#b0c4de" cellspacing="10">
      <tr>
        <td align="right">Name:</td>
        <td><asp:TextBox id="txt_name" runat="server"/></td>
        <td>
        <asp:RequiredFieldValidator
             id="reqfieldval_name"
             ControlToValidate="txt_name" 
             ErrorMessage="Name"
             Text="*" 
             runat="server"/>
        </td>
      </tr>
      <tr>
        <td align="right">Card Type:</td>
        <td>
        <asp:RadioButtonList id="rlist_type" 
             RepeatLayout="Flow"
             runat="server">
               <asp:ListItem>Diners</asp:ListItem>
               <asp:ListItem>MasterCard</asp:ListItem>
               <asp:ListItem>Visa</asp:ListItem>
        </asp:RadioButtonList>
        </td>
        <td>
        <asp:RequiredFieldValidator
             id="reqfieldval_type"
             ControlToValidate="rlist_type"
             ErrorMessage="Card Type"
             InitialValue=""
             Text="*"
             runat="server"/>
        </td>
      </tr>
      <tr>
        <td align="right">Credit Card Number:</td>
        <td><asp:TextBox id="txt_no" runat="server"/></td>
        <td>
        <asp:RequiredFieldValidator
             id="reqfieldval_no"
             ControlToValidate="txt_no" 
             ErrorMessage="Credit Card Number"
             Text="*" 
             runat="server"/>
        </td>
      </tr>
      <tr>
        <td></td>
        <td>
        <asp:Button id="b1" Text="Submit" runat="server"/>
        </td>
        <td></td>
      </tr>
    </table>
    </td>
    <td valign=top>
    <table>
      <tr>
        <td>
        <asp:ValidationSummary id="valSum" 
             HeaderText="Enter a value in the following fields:"
             DisplayMode="BulletList"
             EnableClientScript="true"
             runat="server"/>
        </td>
      </tr>
    </table>
    </td>
  </tr>
</table>
</form>
</body>
</html>

Example 2

In the following example we use the ValidationSummary control to display a message box of the fields that are required but left empty by the user:

<html>
<body>
<form runat="server">
<table>
  <tr>
    <td>
    <table bgcolor="#b0c4de" cellspacing="10">
      <tr>
        <td align="right">Name:</td>
        <td><asp:TextBox id="txt_name" runat="server"/></td>
        <td>
        <asp:RequiredFieldValidator
             id="reqfieldval_name"
             ControlToValidate="txt_name" 
             ErrorMessage="Name"
             Text="*" 
             runat="server"/>
        </td>
      </tr>
      <tr>
        <td align="right">Card Type:</td>
        <td>
        <asp:RadioButtonList id="rlist_type" 
             RepeatLayout="Flow"
             runat="server">
               <asp:ListItem>Diners</asp:ListItem>
               <asp:ListItem>MasterCard</asp:ListItem>
               <asp:ListItem>Visa</asp:ListItem>
        </asp:RadioButtonList>
        </td>
        <td>
        <asp:RequiredFieldValidator
             id="reqfieldval_type"
             ControlToValidate="rlist_type"
             ErrorMessage="Card Type"
             InitialValue=""
             Text="*"
             runat="server"/>
        </td>
      </tr>
      <tr>
        <td align="right">Credit Card Number:</td>
        <td><asp:TextBox id="txt_no" runat="server"/></td>
        <td>
        <asp:RequiredFieldValidator
             id="reqfieldval_no"
             ControlToValidate="txt_no" 
             ErrorMessage="Credit Card Number"
             Text="*" 
             runat="server"/>
        </td>
      </tr>
      <tr>
        <td></td>
        <td>
        <asp:Button id="b1" Text="Submit" runat="server"/>
        </td>
        <td></td>
      </tr>
    </table>
    </td>
    <td valign=top>
    <table>
      <tr>
        <td>
        <asp:ValidationSummary id="valSum" 
             HeaderText="Enter a value in the following fields:"
             ShowMessageBox="true"
             ShowSummary="false"
             EnableClientScript="true"
             runat="server"/>
        </td>
      </tr>
    </table>
    </td>
  </tr>
</table>
</form>
</body>
</html>


Back

Jump to: Top of Page or HOME or Printer Friendly Printer friendly page


Search W3Schools:


What Others Say About Us

Does the world know about us? Check out these places:

Dogpile Alta Vista MSN Google Excite Lycos Yahoo Ask Jeeves


We Help You For Free. You Can Help Us!


W3Schools is for training only. We do not warrant its correctness or its fitness for use. The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 1999-2002 by Refsnes Data. All Rights Reserved


Validate How we converted to XHTML Validate

IISCart
ASP Ecommerce & Shopping Cart


Your own Web Site?

Read W3Schools
Hosting Tutorial



$15 Domain Name
Registration
Save $20 / year!



Advertise
at W3Schools

Only 0.5 CPM



SELECTED LINKS

University Online
Master Degree
Bachelor Degree


Web Software

The Future of
Web Development


Jobs and Careers

Web Security
Web Statistics
Web Standards


PARTNERS

W3Schools
TopXML
VisualBuilder
XMLPitstop
DevelopersDex
DevGuru
Programmers Heaven
The Code Project
Tek Tips Forum
ZVON.ORG
TopXML Search