Tuesday, 24 July 2012

ASP.NET Validation Controls with example | Range validator in ASP.NET and how to use the range validator in ASP.NET

                                Hi Friends , in this article I will explain about the Range validator and how to use the range validator 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.
                               The most important properties in the RangeValidator are MaximumValue, MinimumValue, and type.


MaximumValue: Specifies the maximum value of the input control
MinimumValue: Specifies the minimum value of the input control
Type: Specifies the data type of the value to check. The types are:
  • Currency
  • Date
  • Double
  • Integer
  • String


The below example will shows the how to use RangeValidator in ASP.NET


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Button" />
    <asp:RangeValidator ID="RangeValidator1" runat="server"
        ErrorMessage="* value should be between 1 to 100"
        ControlToValidate="TextBox1" MaximumValue="100" MinimumValue="1" Type="Integer">
    </asp:RangeValidator>
    </form>
</body>
</html>

When we run the above code if  TextBox1 value is not between 1 to 100 then it will shows the error ="* value should be between 1 to 100.

No comments:

Post a Comment

© 2012-2014 Aspdotnet-Kishore.blogspot.com. All Rights Reserved.
The content is copyrighted to Kishore and may not be reproduced on other websites without permission from the owner.