RangeValidator Class

Validates that another control's value falls within an allowable range.

public class System.Web.UI.MobileControls.RangeValidator : 
   System.Web.UI.MobileControls.BaseValidator

Remarks

The minimum and maximum values of the range are provided either directly or by reference to another control. This class behaves identically to the ASP.NET System.Web.UI.WebControls.RangeValidator control.

By default, Command controls on a form raise validator controls on the form to perform validation when the form is submitted to the server. To disable automatic validation, set the CausesValidation property on the Command controls to false.

Example

The following code example requires a user to enter a number from 1 to 23. It uses both the RangeValidator control and the RequiredFieldValidator Control control to validate user entries.

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

<script language="vb" runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
   If Not IsPostBack Then
      Valid1.ControlToValidate = "TextBox1"
      Valid1.Type = ValidationDataType.Integer
      Valid1.MaximumValue = "23"
      Valid1.MinimumValue = "1"
   End If
End Sub

Protected Sub Submit_Click(sender As Object, e As EventArgs)
   If Page.IsValid Then
      ActiveForm = Form2
   End If
End Sub

</script>

<mobile:Form id="Form1" runat="server">
  <mobile:Label runat="server">
   Please enter an integer from 1 through 23
  </mobile:Label>
  
  <mobile:TextBox id="TextBox1" runat="server"/>

   <mobile:RangeValidator id="Valid1" runat="server">
      Invalid number
   </mobile:RangeValidator>

   <mobile:RequiredFieldValidator ControlToValidate="TextBox1" 
      runat="server">
      A number is required
   </mobile:RequiredFieldValidator>

   <mobile:Command runat="server" OnClick="Submit_Click">
      Submit
   </mobile:Command>

</mobile:Form>

<mobile:Form id="Form2" runat="server">
   <mobile:Label runat="server">Number is submitted</mobile:Label>
</mobile:Form>
[C#]
<%@ Page Inherits=
   "System.Web.UI.MobileControls.MobilePage" Language="C#" %>
<%@ Register TagPrefix="mobile"
    Namespace="System.Web.UI.MobileControls"
    Assembly="System.Web.Mobile" %>

<script language="c#" runat="server">

void Page_Load(Object sender, EventArgs e)
{
   if (!IsPostBack)
   {
      Valid1.ControlToValidate = "TextBox1";
      Valid1.Type = ValidationDataType.Integer;
      Valid1.MaximumValue = "23";
      Valid1.MinimumValue = "1";
   }
}

protected void Submit_Click(Object sender, EventArgs e)
{
   if (Page.IsValid)
   {
      ActiveForm = Form2;
   }
}

</script>

<mobile:Form id="Form1" runat="server">
  <mobile:Label runat="server">
   Please enter an integer from 1 through 23
  </mobile:Label>
  
  <mobile:TextBox id="TextBox1" runat="server"/>

   <mobile:RangeValidator id="Valid1" runat="server">
      Invalid number
   </mobile:RangeValidator>

   <mobile:RequiredFieldValidator ControlToValidate="TextBox1" 
      runat="server">
      A number is required
   </mobile:RequiredFieldValidator>

   <mobile:Command runat="server" OnClick="Submit_Click">
      Submit
   </mobile:Command>

</mobile:Form>

<mobile:Form id="Form2" runat="server">
   <mobile:Label runat="server">Number is submitted</mobile:Label>
</mobile:Form>

Requirements

Namespace: System.Web.UI.MobileControls

Assembly: System.Web.Mobile

See Also

RangeValidator Control | BaseValidator Class | CompareValidator Class | CustomValidator Class | RegularExpressionValidator Class | RequiredFieldValidator Class | ValidationSummary Class