当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > Validation服务器控件:ValidationSummary控件

ASP.NET
FreeTextBox(版本3.1.6)在ASP.Net 2.0中使用方法
.NET 常用功能和代码小结
在 .NET Framework 2.0 中未处理的异常导致基于 ASP.NET 的应用程序意外退出
asp.net IList查询数据后格式化数据再绑定控件
asp.net sql存储过程
asp.net 简单实现禁用或启用页面中的某一类型的控件
asp.net(c#)获取内容第一张图片地址的函数
The remote procedure call failed and did not execute的解决办法
ASP.NET 在线文件管理
asp.net 读取并修改config文件实现代码
ASP.NET Cookie 操作实现
asp.net Silverlight中的模式窗体
Silverlight中动态获取Web Service地址
asp.net Silverlight应用程序中获取载体aspx页面参数
asp.net 水晶报表隔行换色实现方法
asp.net 获取Gridview隐藏列的值
手动把asp.net的类生成dll文件的方法
asp.net 使用ObjectDataSource控件在ASP.NET中实现Ajax真分页
动态指定任意类型的ObjectDataSource对象的查询参数
asp.net Md5的用法小结

ASP.NET 中的 Validation服务器控件:ValidationSummary控件


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 85 ::
收藏到网摘: n/a

阅读此文请先查看软晨学习网的: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>