Hi Friends , in this article I will explain about the Range
validator and how to use the range validator in ASP.NET
I already explained in the previous article ASP.NET Validation Controls with example | How to use Validation Controls in ASP.NET | RequiredFieldValidation Control in ASP.NET,ASP.NET Validation Controls with example | How to use ControlValidator in ASP.NET | ControlValidator Control 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