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

ASP.NET
二级域名Cookie问题的解决方法
如何为asp.net网站项目添加子项目
asp.net用url重写URLReWriter实现任意二级域名
asp.net 序列化and反序列化演示
asp.net Timer的使用方法
AjaxControlToolKit DropDownExtender(下拉扩展控件)使用方法
AjaxControlToolKit CalendarExtender(日历扩展控件)的使用方法
让GridView只显示特定用户的数据的方法
让GridView只更新某些特定的数据的方法
ajaxControlToolkit中CascadingDropDown的用法说明
axp.net ScriptManager的简单用法
把程序集安装到全局程序集缓存中的步骤
引用全局程序集缓存内的程序集的方法
asp.net COOKIES需要注意的一点
asp.net UrlReWriter使用经验小结
页面导出为Excel的时间格式的问题
asp.net cookie清除的代码
Asp.net XMLHTTP封装类(GET,Post发送和接收数据)
ASP.NET XmlHttp跨域访问实现代码
Asp.NET 随机码生成基类(随机字母,随机数字,随机字母+数字)

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 195 ::
收藏到网摘: 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>