ASP.NET Mobile ValidationSummary Control[转]

Definition and Usage
定义和用法

The ValidationSummary control is used to display a summary of all validation errors occurred in a Web page.
ValidationSummary 控件的作用是:显示页面中所有的验证错误。

The error message displayed in this control is specified by the ErrorMessage property of each validation control. If the ErrorMessage property of the validation control is not set, no error message is displayed for that validation control.
在控件中显示的错误信息将通过每个验证控件中的ErrorMessage属性指定。如果验证控件的ErrorMessage属性并为设置,那么验证控件中将不会显示任何错误信息。


Properties
属性

Property
属性
Value
Description
描述
Alignment left
center
right
Optional. How to align the control
可选参数。指定控件的排列方式
BackColor rgb(x,x,x)
#xxxxxx
colorname
Optional. A background color for the control
可选参数。指定控件的背景颜色
BackLabel backlabel Optional. Specifies a text that serves as a link to "go back" that will be displayed on the validation summary page
可选参数。指定在验证摘要页面上显示的“返回”标签
ForeColor rgb(x,x,x)
#xxxxxx
colorname
Optional. A foreground color for the control
可选参数。指定控件的前景色
FormToValidate form_id Optional. Specifies the id of the form to validate
可选参数。指定需要验证的表单id
 
Font-Bold false
true
Optional. Specifies whether or not the text in the control should be bold
可选参数。指定控件中的文本字体是否以粗体显示
Font-Italic false
true
Optional. Specifies whether or not the text in the control should be italic
可选参数。指定控件中的文本字体是否以斜体显示
Font-Name fontname Optional. Specifies the font name of the text in the control
可选参数。指定空间中的文本字体名称
Font-Size normal
small
large
Optional. Specifies the font size of the text in the control
可选参数。指定空间中的文本字体尺寸
id unique_name Optional. A unique id for the control
可选参数。为空间指定一个独立的id
runat "server" Required. Specifies that the control is a server control
必要参数。指定该控件为服务器控件
StyleReference name_of_style_element Optional. Specifies a reference to a style to be applied to the control
可选参数。指定一个应用于控件的样式参数
Wrapping wrap
nowrap
Optional. Specifies whether or not the text in the control should wrap
可选参数。指定控件中的文本是否允许被嵌套

Example 1
案例1

The following example contains two forms in an .aspx file. The first form has a label with the text "Please enter a number from 1 through 100", an input box to input a number, a RangeValidator control that checks that the input value is a number from 1 through 100, a RequiredFieldValidator control that checks that the input field isn't empty, and a submit button. The second form is activated by the submit button on the first form, and displays a response. If one of  the input value did not validate, the ValidationSummary control will display (in a list) the text in the ErrorMessage property for each control that did not validate:
下面的案例包含了 .aspx 文件中的两张表单。第一张表单包含一个名为“Please enter a number from 1 through 100” 的标签,一个输入框,一个用于确认输入值范围从数字1-100的RangeValidator 控件,以及一个提交按钮。第二张页面将被第一张页面中的提交按钮激活。如果输入值中的其中一个无效,那么ValidationSummary 控件将在每个无效控件的ErrorMessage属性中显示错误文本列表:

<%@ Page 
Inherits="System.Web.UI.MobileControls.MobilePage"%>
<%@ Register TagPrefix="Mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<script runat="server">
sub page2(Sender as Object,E as EventArgs)
ActiveForm=f2
end sub
</script>

<Mobile:Form id="f1" runat="server">
<Mobile:Label runat="server">

Please enter a number from 1 through 100
</Mobile:Label>
  <Mobile:TextBox id="txt1" runat="server"/>
  <Mobile:RangeValidator
ControlToValidate="txt1"

Type="Integer"
MaximumValue="100"
MinimumValue="1"
ErrorMessage="Invalid number"
runat="server" />
  <Mobile:RequiredFieldValidator
ControlToValidate="txt1"
ErrorMessage="A number is required"
runat="server" />
  <Mobile:Command runat="server"

OnClick="page2">Show errors in Summary
</Mobile:Command>
</Mobile:Form>
<Mobile:Form id="f2" runat="server">
<Mobile:Label runat="server">

Your input is valid if no error is shown below.
</Mobile:Label>
<Mobile:ValidationSummary FormToValidate="f1"
HeaderText="Error listed below:"
BackLabel="Back to main frame" runat="server" />

</Mobile:Form>

posted on 2009-03-17 17:20  黄裳  阅读(141)  评论(0)    收藏  举报

导航