您的位置:首页 > 其它

移动设备的Web应用程序开发----(验证和列表)

2003-10-28 23:46 288 查看

移动.NET输入验证

验证控件用来验证用户输入的数据。

验证控件

验证控件用来验证用户输入的数据。
验证控件允许你去验证输入控件(比如:TextBox)并且当验证失败的时候显示消息。
每个验证控件完成特定类型的验证(比如:不是指定的值或者不是指定的范围)。
默认情况下,当命令控件被点击得失后页面验证才处理。设置控件的CausesValidation属性为false后当控件被点击时你可以阻止页面的验证(和ASP.NET的模式一样设置命令控件(可能激发服务器事件的)的CausesValidation可以不用激发验证逻辑)。

验证输入

这个页面包含两个表单:

<%@ 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>
第一个表单有一个Text属性是Age的Label控件,一个输入年龄的输入框以及一个提交按钮。
通过点击第一个页面的提交按钮后第二个页面被激活,显示相应。
如果验证输入错误,错误消息被显示出来。
当应用程序运行在移动设备上,这两个页面看起来象下面的样子:

Age?

Form 2

You are 21 years old

ValidationSummary 控件

前面的例子使用CompareValidator控件验证输入的信息。输入信息的验证通过验证控件的属性ContolToValidate定义。
你也可以实用ValidationSummary控件的属性FormToValidate,去验证表单里的所有的输入信息。(功能和ASP.NET一样)
这种方式你可以用错误的摘要信息替换原来的单个错误显示。

验证控件参考

Name
Function
CompareValidatorCompares two values
CustomValidatorProvides custom validation
RangeValidatorValidates a range
RegularExpressionValidatorValidates an expression
RequiredFieldValidatorValidates required data
ValidationSummaryDisplays a validation summary
要得到包括属性方法、事件以及更多实例的控件完整参考,请参考”Mobile Reference”页面。(译者注:参考原始页面或者MSDN。)

移动.NET列表

移动列表控件支持不同的输入和显示特性。

从List中选择

这个页面有两个表单:

<%@ Page

Inherits=
"System.Web.UI.MobileControls.MobilePage"%>
<%@ Register
TagPrefix="Mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<script runat="server">
Sub Show_Price(sender As Object,e As ListCommandEventArgs)
text1.Text=e.ListItem.Text & "=" & e.ListItem.Value
ActiveForm=f2
End Sub

</script>

<Mobile:Form id="f1" runat="server">
<Mobile:List runat="server"
OnItemCommand="Show_Price">
<Item text="Volvo" value="$30,000" />
<Item text="BMW" value="$32,000" />
<Item text="Audi" value="$34,000" />
</Mobile:List>
</Mobile:Form>

<Mobile:Form id="f2" runat="server">
<Mobile:Label runat="server" id="text1" />
</Mobile:Form>
第一个表单有一个车的列表。
第二个页面显示价钱。当在第一个页上选择一个车这个页面就被激活。
当这个应用程序运行在移动的设备上这两个页面看起来就像下面的:
Form 1

Volvo
BMW
Audi

Form 2

Volvo=$30,000

移动.NET选择列表

SelectionList控件支持下拉框,复选框以及单选按钮。

SelectionList

这个移动页面使用SelectionList让用户选择车:

<%@ Page
Inherits=
"System.Web.UI.MobileControls.MobilePage"%>
<%@ Register
TagPrefix="Mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>

<script runat="server">
Sub Car_Click(sender as Object, e as EventArgs)
ActiveForm=f2
t1.text=cars.Selection.Value
End Sub
</script>

<Mobile:Form id="f1" runat="server">
<Mobile:SelectionList runat="server" id="cars" >
<Item Text="Volvo" Value="$30,000" />
<Item Text="BMW" Value="$32,000" />
<Item Text="Audi" Value="$34,000" />
</Mobile:SelectionList>
<Mobile:Command runat="server"
OnClick="Car_Click" Text="Submit" />
</Mobile:Form>

<Mobile:Form id="f2" runat="server">
<Mobile:Label id="t1" runat="server" />
</Mobile:Form>
当这个页面显示在移动设备上的时候,页面的导航和显示功能将为不同的设备编译不同的显示特性。(译者注:设备不同看到的页面也不同但是功能是一样的)
有些设备,比如掌上电脑,它可能显示成下拉列表选择表单。在手机上它可能显示为一个选项列表的选择表单。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: