Validation Server Controls->ASP.NET ValidationSummary Control

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

Examples

Validationsummary
ASPX Source:

<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
     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
     ControlToValidate="rlist_type"
     ErrorMessage="Card Type"
     InitialValue=""
     Text="*"
     runat="server"/>
     </td>
   </tr>
   <tr>
     <td></td>
     <td><asp:Button id="b1" Text="Submit" runat="server"/></td>
     <td></td>
   </tr>
</table>
</td>
</tr>
</table>
<br />
<asp:ValidationSummary
HeaderText="You must enter a value in the following fields:"
DisplayMode="BulletList"
EnableClientScript="true"
runat="server"/>
</form>

</body>
</html>

Output Result:
Name:  
Card Type:

 

 

If you have entered nothing into "Name: textbox" and have not selected the radio lists and then click the button "Submit" ,it will show :
Name: *
Card Type:

*

You must enter a value in the following fields:
  • Name
  • Card Type 

If you have entered "shaohai" into "Name: textbox" and have selected  Diners of the radio lists and then click the button "Submit" ,it will show :

Name:  
Card Type:

 
 

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

Validationsummary 2
ASPX Source:

<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
     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
     ControlToValidate="rlist_type"
     ErrorMessage="Card Type"
     InitialValue=""
     Text="*"
     runat="server"/>
     </td>
   </tr>
   <tr>
     <td></td>
     <td><asp:Button id="b1" Text="Submit" runat="server"/></td>
     <td></td>
   </tr>
</table>
</td>
</tr>
</table>
<asp:ValidationSummary
ShowMessageBox="true"
ShowSummary="false"
HeaderText="You must enter a value in the following fields:"
EnableClientScript="true"
runat="server"/>
</form>

</body>
</html>

Output Result:
Name:  
Card Type:

 

If you have entered nothing into "Name: textbox" and have not selected the radio lists and then click the button "Submit" ,it will show :


If you have entered "shaohai" into "Name: textbox" and have not selected the radio lists and then click the button "Submit" ,it will show :


If you have entered "shaohai" into "Name: textbox" and have not selected the radio lists and then click the button "Submit" ,it will show :
Name:  
Card Type:

 
 

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

posted on 2007-03-29 15:50  改变热爱  阅读(253)  评论(0)    收藏  举报

导航