Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

RangeValidator Control

.NET Framework 1.1

The RangeValidator control validates that the values of another control fall within an allowable range, where the minimum and maximum are provided either directly or by reference to another control.

In terms of validation, this control behaves identically to the ASP.NET System.Web.UI.WebControls.RangeValidator control.

Mobile Controls Syntax

Required properties, defaults, and code-featured elements are noted in bold type.

<mobile:RangeValidator
   runat="server"
   id="id"
   Font-Name="fontName"
   Font-Size="{NotSet|Normal|Small|Large}"
   Font-Bold="{NotSet|False|True}"
   Font-Italic="{NotSet|False|True}"
   ForeColor="foregroundColor"
   BackColor="backgroundColor"
   Alignment="{NotSet|Left|Center|Right}"
   StyleReference="styleReference"
   Wrapping="{NotSet|Wrap|NoWrap}"

   ControlToValidate="IdOfTargetControl"
   Display="{None|Static|Dynamic }
   ErrorMessage="ErrorTextForSummary"
   MinimumValue="minValue"
   MaximumValue="maxValue"
   Text="errorText"
   Type={ Currency|DateTime|Double|Integer|String }>
innerText
</mobile:RangeValidator>

Containment Rules

The following controls can contain a RangeValidator control.

Control Comments
System.Web.UI.MobileControls.Form Can contain any number of RangeValidator controls.
System.Web.UI.MobileControls.Panel Can contain any number of RangeValidator controls.

The RangeValidator control cannot contain any other controls.

Device Templates

None.

Device-Specific Behavior

When any validator is rendered, the device-specific nature of its rendering is exactly the same as the device-specific rendering of the Label control, except that the StyleReference property for the control is initially set to Error. When this happens, the control will use the error style in the page style sheet or, if none exists, it will use the system default style sheet.

Example

The following example requires a user to enter a number from 1 through 23. It uses both the RangeValidator control and the RequiredFieldValidator 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">

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="number" runat="server"/>

   <mobile:RangeValidator ControlToValidate="number"
      Type="Integer"
      MaximumValue="23"
      MinimumValue="1"
      runat="server">
      Invalid number
   </mobile:RangeValidator>

   <mobile:RequiredFieldValidator ControlToValidate="number" 
      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">

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="number" runat="server"/>

   <mobile:RangeValidator ControlToValidate="number"
      Type="Integer"
      MaximumValue="23"
      MinimumValue="1"
      runat="server">
      Invalid number
   </mobile:RangeValidator>

   <mobile:RequiredFieldValidator ControlToValidate="number" 
      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>

See Also

RangeValidator Class | RangeValidator Class Members | RangeValidator Control

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.