ValidationSummary.ShowSummary 属性
定义
获取或设置一个值,该值指示是否内联显示验证摘要。Gets or sets a value indicating whether the validation summary is displayed inline.
public:
property bool ShowSummary { bool get(); void set(bool value); };
[System.ComponentModel.Bindable(true)]
public bool ShowSummary { get; set; }
public bool ShowSummary { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.ShowSummary : bool with get, set
member this.ShowSummary : bool with get, set
Public Property ShowSummary As Boolean
属性值
如果内联显示验证摘要,则为 true;否则为 false。true if the validation summary is displayed inline; otherwise, false. 默认值为 true。The default is true.
- 属性
示例
下面的代码示例演示如何使用 ShowMessageBox 和 ShowSummary 属性来指定在消息框和网页上都显示验证摘要。The following code example demonstrates how to use the ShowMessageBox and ShowSummary properties to specify that the validation summary is displayed in both a message box and on the Web page.
重要
此示例具有一个接受用户输入的文本框,这是一个潜在的安全威胁。This example has a text box that accepts user input, which is a potential security threat. 默认情况下,ASP.NET 网页验证用户输入是否不包含脚本或 HTML 元素。By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 有关详细信息,请参阅脚本侵入概述。For more information, see Script Exploits Overview.
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ValidationSummary Sample</title>
</head>
<body>
<h3>ValidationSummary Sample</h3>
<br />
<form id="form1" runat="server">
<table cellpadding="10">
<tr>
<td>
<table style="background-color:#eeeeee; padding:10">
<tr>
<td colspan="3">
<b>Credit Card Information</b>
</td>
</tr>
<tr>
<td align="right">
Card Type:
</td>
<td>
<asp:RadioButtonList id="RadioButtonList1"
RepeatLayout="Flow"
runat="server">
<asp:ListItem>MasterCard</asp:ListItem>
<asp:ListItem>Visa</asp:ListItem>
</asp:RadioButtonList>
</td>
<td align="center" rowspan="1">
<asp:RequiredFieldValidator
id="RequiredFieldValidator1"
ControlToValidate="RadioButtonList1"
ErrorMessage="Card Type. "
Display="Static"
InitialValue="" Width="100%" runat="server">
*
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
Card Number:
</td>
<td>
<asp:TextBox id="TextBox1" runat="server" />
</td>
<td>
<asp:RequiredFieldValidator
id="RequiredFieldValidator2"
ControlToValidate="TextBox1"
ErrorMessage="Card Number. "
Display="Static"
Width="100%" runat="server">
*
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button
id="Button1"
text="Validate"
runat="server" />
</td>
<td></td>
</tr>
</table>
</td>
<td valign="top">
<table cellpadding="20">
<tr>
<td>
<asp:ValidationSummary
id="valSum"
DisplayMode="BulletList"
runat="server"
ShowSummary="True"
HeaderText="You must enter a value in the following fields:"
Font-Names="verdana"
Font-Size="12"/>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ValidationSummary Sample</title>
</head>
<body>
<h3>ValidationSummary Sample</h3>
<br />
<form id="form1" runat="server">
<table cellpadding="10">
<tr>
<td>
<table style="background-color:#eeeeee; padding:10">
<tr>
<td colspan="3">
<b>Credit Card Information</b>
</td>
</tr>
<tr>
<td align="right">
Card Type:
</td>
<td>
<asp:RadioButtonList id="RadioButtonList1"
RepeatLayout="Flow"
runat="server">
<asp:ListItem>MasterCard</asp:ListItem>
<asp:ListItem>Visa</asp:ListItem>
</asp:RadioButtonList>
</td>
<td align="Center" rowspan="1">
<asp:RequiredFieldValidator
id="RequiredFieldValidator1"
ControlToValidate="RadioButtonList1"
ErrorMessage="Card Type. "
Display="Static"
InitialValue="" Width="100%" runat="server">
*
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
Card Number:
</td>
<td>
<asp:TextBox id="TextBox1" runat="server" />
</td>
<td>
<asp:RequiredFieldValidator
id="RequiredFieldValidator2"
ControlToValidate="TextBox1"
ErrorMessage="Card Number. "
Display="Static"
Width="100%" runat="server">
*
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button
id="Button1"
text="Validate"
runat="server" />
</td>
<td></td>
</tr>
</table>
</td>
<td valign="top">
<table cellpadding="20">
<tr>
<td>
<asp:ValidationSummary
id="valSum"
DisplayMode="BulletList"
runat="server"
ShowSummary="True"
HeaderText="You must enter a value in the following fields:"
Font-Names="verdana"
Font-Size="12"/>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
注解
除了属性外,还可以使用此属性 ShowMessageBox 来控制验证摘要的显示位置。This property can be used in addition to the ShowMessageBox property to control where the validation summary is displayed. 如果将此属性设置为 true ,则验证摘要将显示在网页上。If this property is set to true, the validation summary is displayed on the Web page.
备注
如果 ShowMessageBox 和 ShowSummary 属性都设置为 true ,则验证摘要将显示在消息框和网页上。If both the ShowMessageBox and ShowSummary properties are set to true, the validation summary is displayed in both a message box and on the Web page.