In this article I’m going to explain how to use RangeValidator in ASP.NET.

RangeValidator control:

          The RangeValidator control is used to check that the user enters an input value that falls between two values. It is possible to check ranges within numbers, dates, and characters.      

I’ve written few articles about validation in ASP.NET. You may refer these articles

            How to use RequiredFieldValidator control in ASP.NET

          How to use CompareFieldValidator control in ASP.NET

          How to use RegularExpressionValidator control in ASP.NET

            Here I’ll show you how to use RangeValidator control. In this demo I’ve used two TextBox controls for get Name and Age from user. I’ve used RangeValidator to validate minimum and maximum age.

Properties:

ü  MinimumValue: Specifies the minimum value of the input control

ü  Maximumvalue: Specifies the maximum value of the input control

ü  ControlToValidate: Gets or sets the input control to validate.

ü  Display: Gets or sets the display behavior of the error message in a validation control.

ü  ErrorMessage: Gets or sets the text for the error message displayed in a ValidationSummary control when validation fails.

ü  SetFocusOnError: Gets or sets a value that indicates whether focus is set to the control specified by the ControlToValidate property when validation fails.

ü  ValidationGroup: Gets or sets the name of the validation group to which this validation control belongs.

 

Designer source code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>Range Validator Demo</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <table>

            <tr>

                <td>

                    Name:

                </td>

                <td>

                    <asp:TextBox ID="txtName" runat="server" ValidationGroup="Submit"></asp:TextBox>

                </td>

                <td>

                </td>

            </tr>         

            <tr>

                <td>

                   Age :

                </td>

                <td>

                    <asp:TextBox ID="txtAge" runat="server" ValidationGroup="Submit"></asp:TextBox>

                </td>

                <td>

                    <asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Age must between 18 to 30"

                                         ControlToValidate="txtAge" MinimumValue="18" MaximumValue="30" Display="Dynamic"

                                          ValidationGroup="Submit" ForeColor="Red"></asp:RangeValidator>

                </td>

            </tr>

            <tr>

                <td colspan="3">

                    <asp:Button ID="btnSubmit" runat="server" Text="Submit" ValidationGroup="Submit" />

                </td>

            </tr>

        </table>

    </div>

    </form>

</body>

</html>



View demo Download
http://www.dotnetfox.com/Document/1051/0Demo1.gif

If you enjoyed this article, get email updates (it's free).


Related Articles
  • How to use RequiredFieldValidator control in ASP.NETIn this article I’m going to explain how to use RequiredFieldValidator control in ASP.NET. The RequiredFieldValidator control is used to make an input control a required field. The validation fails if control doesn’t contains any values. By default, the initial value is an empty string ("").
  • How to use CompareFieldValidator control in ASP.NETIn this article I’m going to explain how to use CompareFieldValidator control in ASP.NET. The CompareFieldValidator control is used to compare the value of one input control to the value of another input control or to a fixed value.
  • How to use RangeValidator control in ASP.NETIn this article I’m going to explain how to use RangeValidator in ASP.NET. The RangeValidator control is used to check that the user enters an input value that falls between two values. It is possible to check ranges within numbers, dates, and characters.

Comments
comments powered by Disqus

Thanks for downloading..!!

×
Subscribe via Email
    
message to display in fancybox