-->
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="txtAge" ErrorMessage="Invalid Age" MinimumValue="18" MaximumValue="80" Type="Integer" />
<%@ Page Language="C#" AutoEventWireup="true" %> <!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 id="Head1" runat="server"> <title></title> <style> .column { float: left; width: 30%; margin-left: 10px; background-color: white; border: solid 1px black; padding: 10px; width: 70%; } fieldset { background-color: #a9a9a9; border: solid 2px #d81a72; color:Black; width:70%; } </style> </head> <body style="width: 70%;"> <form id="form1" runat="server" > <div class="column"> <fieldset> <legend>Range Validator Demo</legend> <asp:Label ID="lblAge" Style="margin-right: 12px;" ValidationGroup="rv" AssociatedControlID="txtAge" runat="server">Age:</asp:Label> <asp:TextBox ID="txtAge" MaxLength="3" ValidationGroup="rv" runat="server"></asp:TextBox> <asp:RangeValidator ID="rvAge" ControlToValidate="txtAge" SetFocusOnError="true" ErrorMessage="Plz Enter Age Between 0 to 150" ValidationGroup="rv" MinimumValue="0" MaximumValue="150" Type="Integer" runat="server"></asp:RangeValidator> <asp:RequiredFieldValidator ID="rfvAge" ControlToValidate="txtAge" ErrorMessage="Enter Age" ValidationGroup="rv" SetFocusOnError="true" runat="server"></asp:RequiredFieldValidator> <br /> <asp:Button runat="server" ID="btnRangeValidate" ValidationGroup="rv" Text="Validate" /> </fieldset> </div> </form> </body> </html>
Thanks for reading Asp.Net RangeValidator Control