<asp:RangeValidator
id="ProgrammaticID"
ControlToValidate="ProgrammaticID of control to validate"
MinimumValue="value"
MaximumValue="value"
Type="DataType"
ErrorMessage="Message to display in ValidationSummary control"
Text="Message to display in control"
ForeColor="value"
BackColor="value"
runat="server" >
</asp:RangeValidator>
The RangeValidator control allows you to check whether a user's entry is between a specified upper and lower boundary. You can check ranges within pairs of numbers, alphabetic characters, and dates. Boundaries are expressed as constants.
Use the ControlToValidate property to specify the input control to validate. The MinimumValue and MaximumValue properties specify the minimum and maximum values of the valid range, respectively.
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional/EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<script runat="server">
protected void ButtonExample_Click(object sender,System.EventArgs e) {
LabelExample.Text = "You entered valid Number.<br>Your Number:" + TextBoxExample.Text.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ASP.Net RangeValidator Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="LabelExample" runat="server"></asp:Label>
<br />
<asp:Label ID="lblTesting" runat="server" Text="Number" AssociatedControlID="TextBoxExample"></asp:Label>
<asp:TextBox ID="TextBoxExample" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorExample" runat="server" ControlToValidate="TextBoxExample" ErrorMessage="Number is required!" Text="*">
</asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidatorExample" runat="server" ControlToValidate="TextBoxExample" MaximumValue="200" MinimumValue="100" Type="Integer" ErrorMessage="You must be input between 100 to 200.">
</asp:RangeValidator>
<br />
<asp:Button ID="ButtonExample" runat="server" Text="Validate Number" OnClick="ButtonExample_Click"/>
</div>
</form>
</body>
</html>
ASP.Net RangeValidator Example, How to <asp:RangeValidator> Control validate a range in asp.net c#
Hot on Web: