Export (0) Print
Expand All

RangeValidator Class

Checks whether the value of an input control is within a specified range of values.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public class RangeValidator : BaseCompareValidator
public class RangeValidator extends BaseCompareValidator
public class RangeValidator extends BaseCompareValidator

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. 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.

NoteNote

Validation succeeds if the input control is empty. Use a RequiredFieldValidator control to make the input control a mandatory field.

NoteNote

The RangeValidator control throws an exception if the value specified by the MaximumValue or MinimumValue property cannot be converted to the specified BaseCompareValidator.Type.

For additional information on validation controls, see BaseValidator.

Accessibility

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.

TopicLocation
How to: Validate Against a Data Type for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Validate Required Entries for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Validate with a Custom Function for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Disable Validation for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Validate Against Values in a Database for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Validate Against a Range of Values for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Validate Against a Specific Value for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Validate Against a Data Type for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Specify Layout for In-Place Messages On ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Validate Required Entries for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Display Server Side Custom Validation Messages for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Test Validity Programmatically for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Validate Against Patterns for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Format Validation Error Messages for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Validate with a Custom Function for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Disable Validation for ASP.NET Server ControlsBuilding ASP .NET Web Applications
Walkthrough: Validating User Input in a Web Forms PageBuilding ASP .NET Web Applications in Visual Studio
How to: Validate Programmatically for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Validate Programmatically for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Format Validation Error Messages for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Validate Against Patterns for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Test Validity Programmatically for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Display Server Side Custom Validation Messages for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Specify Layout for In-Place Messages On ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Validate Against a Specific Value for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Validate Against a Range of Values for ASP.NET Server ControlsBuilding ASP .NET Web Applications
How to: Validate Against Values in a Database for ASP.NET Server ControlsBuilding ASP .NET Web Applications

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.


<%@ Page Language="C#" AutoEventWireup="True" %>

<html>

<head>

   <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 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>


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft