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 page is activated by the submit button on the first page, and displays a response. If the input value validates as an error, an error message is displayed:
下面的案例包含了 .aspx 文件中的两张表单。第一张表单包含一个名为“Please enter a number from 1 through 100” 的标签,一个输入框,一个用于确认输入值范围从数字1-100的RangeValidator 控件,以及一个提交按钮。第二张页面将被第一张页面中的提交按钮激活。如果输入值确认出现错误,那么将显示一段错误信息:
<%@ 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 lbl2.Text="You entered number " & txt1.text end if 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"
Text="Invalid number" runat="server" />
<Mobile:RequiredFieldValidator ControlToValidate="txt1" Text="A number is required"
runat="server" />
<Mobile:Command runat="server" OnClick="page2">Submit </Mobile:Command>
</Mobile:Form>
<Mobile:Form id="f2" runat="server"> <Mobile:Label id="lbl2" runat="server" />
</Mobile:Form>
|