程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> ASP.NET >> 關於ASP.NET >> Validation服務器控件:ValidationSummary控件

Validation服務器控件:ValidationSummary控件

編輯:關於ASP.NET

閱讀此文請先查看網頁教學網的:ASP.NET入門教程:Validation服務器控件,簡單講述了Web服務器控件的使用方法。

定義和用法

ValidationSummary 控件用於在網頁、消息框或在這兩者中內聯顯示所有驗證錯誤的摘要。顯示 Web 頁上所有驗證錯誤的列表。

在該控件中顯示的錯誤消息是由每個驗證控件的 ErrorMessage 屬性規定的。如果未設置驗證控件的 ErrorMessage 屬性,就不會為那個驗證控件顯示錯誤消息。

屬性

屬性 描述 DisplayMode

如何顯示摘要。合法值有:

  • BulletList
  • List
  • SingleParagraph
EnableClientScript 布爾值,規定是否啟用客戶端驗證。 Enabled 布爾值,規定是否啟用驗證控件。 ForeColor 該控件的前景色。 HeaderText ValidationSummary 控件中的標題文本。 id 控件的唯一 id。 runat 規定該控件是一個服務器控件。必須設置為 "server"。 ShowMessageBox 布爾值,指示是否在消息框中顯示驗證摘要。 ShowSummary 布爾值,規定是否顯示驗證摘要。

實例

<asp:ValidationSummary
    AccessKey="string"
    BackColor="color name|#dddddd"
    BorderColor="color name|#dddddd"
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
        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"
    Style="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>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved