ValidationSummary.ShowSummary 屬性

定義

取得或設定值,指出是否內嵌顯示驗證摘要。

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

屬性值

Boolean

如果內嵌顯示驗證摘要,則為 true,否則為 false。 預設為 true

屬性

範例

下列程式碼範例示範如何使用 ShowMessageBoxShowSummary 屬性來指定驗證摘要會顯示在訊息方塊和網頁上。

重要

這個範例有一個可接受使用者輸入的文字方塊,這可能會造成安全性威脅。 根據預設,ASP.NET Web 網頁會驗證使用者輸入未包含指令碼或 HTML 項目。 如需詳細資訊,請參閱 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 還可以使用這個屬性來控制顯示驗證摘要的位置。 如果這個屬性設定為 true ,驗證摘要會顯示在網頁上。

注意

ShowMessageBox如果 和 ShowSummary 屬性都設定為 true ,驗證摘要會顯示在訊息方塊和網頁上。

適用於

另請參閱