Checks whether the value of an input control is within a specified range of values.
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _ <AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _ Public Class RangeValidator _ Inherits BaseCompareValidator
Dim instance As RangeValidator
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)] public class RangeValidator : BaseCompareValidator
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)] [AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)] public ref class RangeValidator : public BaseCompareValidator
public class RangeValidator extends BaseCompareValidator
<asp:RangeValidator />
The RangeValidator control tests whether the value of an input control is within a specified range.
The RangeValidator control uses four key properties to perform its validation. The ControlToValidate property contains the input control to validate. The MinimumValue and MaximumValue properties specify the minimum and maximum values of the valid range.
The BaseCompareValidator..::.Type property is used to specify the data type of the values to compare. The values to compare are converted to this data type before the validation operation is performed.
When the Type property is set to Date and the current calendar type is non-Gregorian, the validator performs server-side validation only. The validator client script supports only Gregorian calendars.
The following table lists the different data types that can be compared.
Data Type
Description
String
A string data type.
Integer
A 32-bit signed integer data type.
Double
A double-precision floating point number data type.
Date
A date data type.
Currency
A decimal data type that can contain currency symbols.
Validation succeeds if the input control is empty. Use a RequiredFieldValidator control to make the input control a mandatory field.
The RangeValidator control throws an exception if the value specified by the MaximumValue or MinimumValue property cannot be converted to the specified BaseCompareValidator..::.Type.
When you use the RangeValidator control inside an UpdatePanel control, make sure that the validator control and the control it is associated with are in the same panel. For more information about using the UpdatePanel control for partial-page updates, see Partial-Page Rendering Overview.
For additional information on validation controls, see BaseValidator.
The markup rendered by default for this control might not conform to accessibility standards such as the Web Content Accessibility Guidelines 1.0 (WCAG) priority 1 guidelines. For details about accessibility support for this control, see ASP.NET Controls and Accessibility.
The following example demonstrates how to create a RangeValidator control on the Web page to determine whether the value entered into an input control is within the comparison range.
This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.
<%@ Page Language="VB" AutoEventWireup="True" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html > <head> <title>RangeValidator Example</title> <script runat="server"> Sub ButtonClick(sender As Object, e As EventArgs) If Page.IsValid Then Label1.Text="Page is valid." Else Label1.Text="Page is not valid!!" End If End Sub </script> </head> <body> <form id="form1" runat="server"> <h3>RangeValidator Example</h3> Enter a number from 1 to 10: <br /> <asp:TextBox id="TextBox1" runat="server"/> <br /> <asp:RangeValidator id="Range1" ControlToValidate="TextBox1" MinimumValue="1" MaximumValue="10" Type="Integer" EnableClientScript="false" Text="The value must be from 1 to 10!" runat="server"/> <br /><br /> <asp:Label id="Label1" runat="server"/> <br /><br /> <asp:Button id="Button1" Text="Submit" OnClick="ButtonClick" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="True" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html > <head> <title>RangeValidator Example</title> <script runat="server"> void ButtonClick(Object sender, EventArgs e) { if (Page.IsValid) { Label1.Text="Page is valid."; } else { Label1.Text="Page is not valid!!"; } } </script> </head> <body> <form id="form1" runat="server"> <h3>RangeValidator Example</h3> Enter a number from 1 to 10: <br /> <asp:TextBox id="TextBox1" runat="server"/> <br /> <asp:RangeValidator id="Range1" ControlToValidate="TextBox1" MinimumValue="1" MaximumValue="10" Type="Integer" EnableClientScript="false" Text="The value must be from 1 to 10!" runat="server"/> <br /><br /> <asp:Label id="Label1" runat="server"/> <br /><br /> <asp:Button id="Button1" Text="Submit" OnClick="ButtonClick" runat="server"/> </form> </body> </html>
for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98