.NET Mobile Input Validation. Explain with an example
Validation controls are used to validate an input control. They provide a message if the validation fails on the control. By default validation is applied on the command event of an input control. One can disable this by setting the input control’s causes validation property to false.
Example:<%@ Page Inherits= "System.Web.UI.MobileControls.MobilePage"%>
<%@ Register TagPrefix="Mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
<script runat="server">
private void Page2(Object Sender, EventArgs e)
{
If (Page.IsValid)
{
ActiveForm=f2;
text2.Text="You are " + age.text + " years old";
}
}
</script>
<Mobile:Form id="f1" runat="server">
<Mobile:CompareValidator runat="server" ControlToValidate="txtage" Type="Integer" ValueToCompare="12" Operator="GreaterThanEqual"> You must be at least 12</Mobile:CompareValidator>
<Mobile:Label runat="server">What is your Age?</Mobile:Label>
<Mobile:TextBox id="txtage" 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>
This will display a message if the user input is less than 12