ValidationSummary 控件用於在網頁、消息框或在這兩者中內聯顯示所有驗證錯誤的摘要。顯示 Web 頁上所有驗證錯誤的列表。
在該控件中顯示的錯誤消息是由每個驗證控件的 ErrorMessage 屬性規定的。如果未設置驗證控件的 ErrorMessage 屬性,就不會為那個驗證控件顯示錯誤消息。
如何顯示摘要。合法值有:
<ASP:ValidationSummary
AccessKey="string"
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderPADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px"> Inset|Outset"
BorderWidth="size"
CSSClass="string"
DisplayMode="List|BulletList|SingleParagraph"
EnableClIEntScript="True|False"
Enabled="True|False"
EnableTheming="True|False"
EnableVIEwState="True|False"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
HeaderText="string"
Height="size"
ID="string"
OnDataBinding="DataBinding event handler"
OnDisposed="Disposed event handler"
OnInit="Init event handler"
OnLoad="Load event handler"
OnPreRender="PreRender event handler"
OnUnload="Unload event handler"
runat="server"
ShowMessageBox="True|False"
ShowSummary="True|False"
SkinID="string"
TabIndex="integer"
ToolTip="string"
ValidationGroup="string"
Visible="True|False"
Width="size"
/>
備注:ValidationSummary 控件允許在單個位置概述網頁上所有驗證控件的錯誤信息。基於 DisplayMode 屬性的值,該摘要可顯示為列表、項目符號列表或單個段落。ValidationSummary 控件中為頁面上每個驗證控件顯示的錯誤信息,是由每個驗證控件的 ErrorMessage 屬性指定的。如果沒有設置驗證控件的 ErrorMessage 屬性,將不會在 ValidationSummary 控件中為該驗證控件顯示錯誤信息。通過設置 HeaderText 屬性,還可以在 ValidationSummary 控件的標題部分指定一個自定義標題。
通過設置 ShowSummary 屬性,可以控制 ValidationSummary 控件是顯示還是隱藏。還可通過將 ShowMessageBox 屬性設置為 true,在消息框中顯示摘要。
下面的代碼示例演示如何使用 ValidationSummary 控件來概述頁上的未通過驗證的輸入控件。
Visual Basic
<h3>ValidationSummary Sample</h3>
<p>
<form id="Form1" runat="server">
<table cellpadding="10">
<tr>
<td>
<table bgcolor="#eeeeee" cellpadding="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="middle" rowspan="1">
<ASP:RequiredFIEldValidator
id="RequiredFIEldValidator1"
ControlToValidate="RadioButtonList1"
ErrorMessage="Card Type."
Display="Static"
InitialValue=""
Width="100%"
Text="*"
runat="server"/>
</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%"
Text="*"
runat=server/>
</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"
EnableClIEntScript="true"
HeaderText="You must enter a value in the following fIElds:"
runat="server"/>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
C#
<h3>ValidationSummary Sample</h3>
<p>
<form id="Form1" runat="server">
<table cellpadding="10">
<tr>
<td>
<table bgcolor="#eeeeee" cellpadding="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="middle" rowspan="1">
<ASP:RequiredFIEldValidator
id="RequiredFIEldValidator1"
ControlToValidate="RadioButtonList1"
ErrorMessage="Card Type."
Display="Static"
InitialValue=""
Width="100%"
Text="*"
runat="server"/>
</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%"
Text="*"
runat=server/>
</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"
EnableClIEntScript="true"
HeaderText="You must enter a value in the following fIElds:"
runat="server"/>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>