定义和用法
ValidationSummary 控件用于显示网页中所有验证错误的摘要。
在该控件中显示的错误消息是由每个验证控件的 ErrorMessage 属性规定的。如果未设置验证控件的 ErrorMessage 属性,就不会为那个验证控件显示错误消息。
属性
| 属性 | 描述 | 
|---|---|
| DisplayMode | 如何显示摘要。合法值有: 
 | 
| EnableClientScript | 布尔值,规定是否启用客户端验证。 | 
| Enabled | 布尔值,规定是否启用验证控件。 | 
| ForeColor | 控件的前景颜色。 | 
| headerText | ValidationSummary 控件中的标题文本。 | 
| id | 控件的唯一 id。 | 
| runat | 规定该控件是一个服务器控件。必须设置为 "server"。 | 
| ShowMessageBox | 布尔值,规定是否在消息框中显示验证摘要。 | 
| ShowSummary | 布尔值,规定 ValidationSummary 控件是否显示或者隐藏。 | 
实例
Validationsummary
<!DOCTYPE HTML> <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>
在本例中,我们使用 ValidationSummary 控件生成了一个留空供用户填写的必填字段的列表。
Validationsummary 2
<!DOCTYPE html> <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>
在本例中,我们使用 ValidationSummary 控件显示了一个留空供用户填写的必填字段的消息框。