.NET Mobile输入检测[转]

Validation Controls are used to validate the data entered by a user.
Validation(检测)控件用于检测用户输入的数据


Validation Controls
Validation(检测)控件

Validation controls are used to validate the data entered by a user.
Validation(检测)控件用于检测用户输入的数据

Validation controls allow you to validate an input control (like a TextBox), and display a message when validation fails.
Validation(检测)控件允许你检测一个输入控件(像一个文本框),并在检测失效时显示一条信息。

Each validation control performs a specific type of validation (like validating against a specific value or a range of values).
每项检测控件执行了一个指定类型的检测(像检测一个特定值或一定范围内的所有值)

By default, page validation is performed when a command control is clicked. You can prevent validation when a control is clicked by setting the CausesValidation property to false.
默认状态下,当命令控件被点击时页面检测会被执行。通过设置CausesValidation(引起检测)属性为假,在控件被点击时检验就不会执行。


Validating Input
检验输入

This page has two forms:
这页有两个窗口
 

<%@ 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)
If Page.IsValid Then
ActiveForm=f2
text2.Text="You are " & age.text & " years old"

end if
End Sub

</script>

<Mobile:Form id="f1" runat="server">
<Mobile:CompareValidator runat="server"
ControlToValidate="age"

Type="Integer"
ValueToCompare="18"
Operator="GreaterThanEqual">
You must be at least 18
</Mobile:CompareValidator>

<Mobile:Label runat="server">Age?</Mobile:Label>

<Mobile:TextBox id="age" runat="server" />
<Mobile:Command OnClick="Page2" runat="server">
Submit</Mobile:Command>

</Mobile:Form>

<Mobile:Form id="f2" runat="server">
<Mobile:Label id="text2" runat="server" />

</Mobile:Form>

The first form has a label with the text "Age?", an input box to input the age, and a submit button.
第一个窗口有文本为"Age?"的一个标签,一个用于输入年龄的输入框,和一个提交按钮

The second page is activated by the submit button on the first page, and displays a response.
第二页被第一页的提交按钮激活,显示了回应。

If the input validates as error, an error message is displayed.
如果输入验证为错误,就会显示错误信息

When the application runs on a mobile device, the two pages will display like this:
当程序在手机部件运行时,两页会这样显示:

Form 1  窗口1

Age?




 

Form 2  窗口2

You are 21 years old






 

 


The ValidationSummary Control
ValidationSummary(验证摘要)控件

The previous example used a CompareValidator control to validate an input field. The field to validate was defined by the attribute ContolToValidate.
前面的例子用了CompareValidator控件检验一个输入区域。检验区域是由ContolToValidate(检验控件).属性定义的

You can also use a ValidationSummary control with the attribute FormToValidate, to validate all the input of a form.
你也可以用有FormToValidate(检验窗口)属性的ValidationSummary(检验摘要)控件,来检验窗口的所有输入。

This way you can display a summary of errors instead of one error at the time.
用这种方法你可以显示所有错误的摘要而不是只显示一个错误。


Validation Controls Reference
检验控件参考

Name名称 Function功能
CompareValidator  比较检验 Compares two values 
比较两个值
CustomValidator  自定义检验 Provides custom validation 
提供自定义检验
RangeValidator  验证范围 Validates a range 
验证范围
RegularExpressionValidator  常规表达式检验 Validates an expression 
检验一个表达式
RequiredFieldValidator  要求区域检验 Validates required data 
检验被要求的数据
ValidationSummary  检验摘要 Displays a validation summary 
显示检验摘要

For a full control reference, including properties methods, events, and more examples, please refer to the "Mobile Reference" page.
为了解完整的控件参考,包括属性方法,事件和更多例子,请看"Mobile Reference"。

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

导航