当前位置:沸点梦工场 > WAP网页设计 > Asp.net wap开发教程 > 浏览文章

ASP.NET 移动控件--ValidationSummary 控件

互联网 2007年06月21日 【字体:

此控件显示窗体呈现过程中发生的所有验证错误的摘要。

移动控件语法
必需的属性、默认值和具有代码特征的元素以粗体显示。

<mobile:ValidationSummary
   runat="server"
   id="id"
   Font-Name="fontName"
   Font-Size="{NotSet|Normal|Small|Large}"
   Font-Bold="{NotSet|False|True}"
   Font-Italic="{NotSet|False|True}"
   ForeColor="foregroundColor"
   BackColor="backgroundColor"
   Alignment="{NotSet|Left|Center|Right}"
   StyleReference="styleReference"
   Wrapping="{NotSet|Wrap|NoWrap}"

   FormToValidate="FormID"
   BackLabel="[BackLabel]">
</mobile:ValidationSummary>
包容规则
以下控件可以包含 ValidationSummary 控件。

控件 说明
System.Web.UI.MobileControls.Form 可以包含任意多个 ValidationSummary 控件。
System.Web.UI.MobileControls.Panel 可以包含任意多个 ValidationSummary 控件。

ValidationSummary 控件不能包含任何其他控件。

设备模板
无。

特定于设备的行为
对于所有呈现,StyleReference 属性最初都设置为 。它将对页样式表使用错误样式,或者如果页的样式表不存在,它将使用系统默认样式表。

ValidationSummary 控件的呈现方式是先显示 HeaderText 属性的值,然后显示包含以下项的 HTML 或 WML 列表:

无效窗体上每个验证程序的 Message 属性。
以无效窗体作为其目标并且文本为 BackLabel 属性的值而呈现的 Link 控件。
在所有设备上,如果您要验证的窗体有效,则 ValidationSummary 控件不呈现任何内容。

设备语言 行为描述
HTML 控件的当前样式按现状应用于所有 HTML 呈现。
WML 每个 Message 属性前面都有一个“-”(连字符后接一个空格)。

示例
此示例演示显示验证错误的两种方法:一种内联方法,另一种是使用摘要格式的方法。

[Visual Basic]
<%@ Page Inherits=
   "System.Web.UI.MobileControls.MobilePage" Language="VB" %>
<%@ Register TagPrefix="mobile"
    Namespace="System.Web.UI.MobileControls"
    Assembly="System.Web.Mobile" %>

<script language="vb" runat="server">

Protected Sub Summary_Click(sender As Object, e As EventArgs)
  ' Hide or show Back link. This is because ValidationSummary
  ' doesn't provide the Back link when validation succeeds.
   BackLink.Visible = Page.IsValid
   ActiveForm = Form2
End Sub

Sub ServerValidate (source As object, args As ServerValidateEventArgs)
  Dim num as Int32
  num = Int32.Parse(number.Text)
  args.IsValid = ((num Mod 2) = 0)
End Sub
</script>

<mobile:Form id="Form1" runat="server">

  <mobile:RangeValidator runat="server"
   ControlToValidate="number"
   Type="Integer"
   MaximumValue="5"
   MinimumValue="1"
   Message="The input number should be with in the range 1 - 5.">

    Please enter a number of value 1 - 5

  </mobile:RangeValidator>

  <mobile:RegularExpressionValidator runat="server"
       ControlToValidate="number"
       ValidationExpression="\b\d{1}\b"
       Message="The input number should be a single digit.">
   Please enter a single digit
  </mobile:RegularExpressionValidator>

  <mobile:CustomValidator ControlToValidate="number"
         OnServerValidate="ServerValidate"
         Message="The input number should be even."
         runat="server">
   Please enter an even number
  </mobile:CustomValidator>

  <mobile:Label runat="server">
   Please enter an even number between 1 to 5
  </mobile:Label>
  <mobile:TextBox id="number" runat="server"/>

  <mobile:Command runat="server">
   Show errors inline if not valid
  </mobile:Command>

  <mobile:Command OnClick="Summary_Click" runat="server">
   Show errors in summary
  </mobile:Command>
</mobile:Form>

<mobile:Form id="Form2" runat="server">
  <mobile:Label runat="server">
   Your input is valid if no error is shown below.
  </mobile:Label>
  <mobile:ValidationSummary FormToValidate="Form1"
                     HeaderText=" listed below:"
                     runat="server"/>
  <mobile:Link id="BackLink" runat="server"
            NavigateUrl="#Form1"
            Visible="False"
            Text="Back" />
</mobile:Form>
[C#]
<%@ Page Inherits=
   "System.Web.UI.MobileControls.MobilePage" Language="C#" %>
<%@ Register TagPrefix="mobile"
    Namespace="System.Web.UI.MobileControls"
    Assembly="System.Web.Mobile" %>

<script language="c#" runat="server">

protected void Summary_Click(Object sender, EventArgs e)
{
  // Hide or show Back link. This is because ValidationSummary
  // doesn't provide the Back link when validation succeeds.
   BackLink.Visible = Page.IsValid;
   ActiveForm = Form2;
}

void
ServerValidate (object source, ServerValidateEventArgs args)
{
   int num = Int32.Parse(number.Text);
   args.IsValid = ((num % 2) == 0);

}
</script>

<mobile:Form id="Form1" runat="server">

  <mobile:RangeValidator runat="server"
   ControlToValidate="number"
   Type="Integer"
   MaximumValue="5"
   MinimumValue="1"
   Message="The input number should be with in the range 1 - 5.">

    Please enter a number of value 1 - 5

  </mobile:RangeValidator>

  <mobile:RegularExpressionValidator runat="server"
       ControlToValidate="number"
       ValidationExpression="\b\d{1}\b"
       Message="The input number should be a single digit.">
   Please enter a single digit
  </mobile:RegularExpressionValidator>

  <mobile:CustomValidator ControlToValidate="number"
         OnServerValidate="ServerValidate"
         Message="The input number should be even."
         runat="server">
   Please enter an even number
  </mobile:CustomValidator>

  <mobile:Label runat="server">
   Please enter an even number between 1 to 5
  </mobile:Label>
  <mobile:TextBox id="number" runat="server"/>

  <mobile:Command runat="server">
   Show errors inline if not valid
  </mobile:Command>

  <mobile:Command OnClick="Summary_Click" runat="server">
   Show errors in summary
  </mobile:Command>
</mobile:Form>

<mobile:Form id="Form2" runat="server">
  <mobile:Label runat="server">
   Your input is valid if no error is shown below.
  </mobile:Label>
  <mobile:ValidationSummary FormToValidate="Form1"
                     HeaderText=" listed below:"
                     runat="server"/>
  <mobile:Link id="BackLink" runat="server"
            NavigateUrl="#Form1"
            Visible="False"
            Text="Back" />
</mobile:Form>