移动设备的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> |
通过点击第一个页面的提交按钮后第二个页面被激活,显示相应。
如果验证输入错误,错误消息被显示出来。
当应用程序运行在移动设备上,这两个页面看起来象下面的样子:
Age? |
You are 21 years old |
ValidationSummary 控件
前面的例子使用CompareValidator控件验证输入的信息。输入信息的验证通过验证控件的属性ContolToValidate定义。你也可以实用ValidationSummary控件的属性FormToValidate,去验证表单里的所有的输入信息。(功能和ASP.NET一样)
这种方式你可以用错误的摘要信息替换原来的单个错误显示。
验证控件参考
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 |
移动.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 |
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> |
有些设备,比如掌上电脑,它可能显示成下拉列表选择表单。在手机上它可能显示为一个选项列表的选择表单。
相关文章推荐
- 移动设备的Web应用程序开发----(验证和列表)
- 【Android开发经验】移动设备的“声波通信/验证”的实现——SinVoice开源项目介绍(三)
- 移动设备的Web应用程序开发----(模拟器)
- 移动设备的Web应用程序开发----(事件和输入)
- 移动设备的Web应用程序开发----(表单)
- 移动设备的Web应用程序开发----(介绍)
- 【Android开发经验】移动设备的“声波通信/验证”的实现——SinVoice开源项目介绍(一)
- 移动设备的Web应用程序开发----(图像和Utility)
- 【Android开发经验】移动设备的“声波通信/验证”的实现——SinVoice开源项目介绍(一)
- 【Android开发经验】移动设备的“声波通信/验证”的实现——SinVoice开源项目介绍(二)
- 移动设备的Web应用程序开发----(介绍)
- 移动设备的Web应用程序开发----(例子)
- 移动设备的Web应用程序开发----(模拟器)
- 【Android开发经验】移动设备的“声波通信/验证”的实现——SinVoice开源项目介绍(一)
- 【Android开发经验】移动设备的“声波通信/验证”的实现——SinVoice开源项目介绍(三)
- Smobiler基于.NET框架开发移动应用内部系统—消息列表功能(开发日志六)
- 移动应用安全开发指南(Android)--数据验证
- 使用ArcGIS Mobile SDK 9.3 开发移动设备应用-中级篇
- 面向移动设备的html5开发框架之比较
- MSDN ASP.NET移动设备开发资料