RangeValidator Example in ASP.NET using C#

RangeValidator Example in ASP.NET using C#


Posted in : ASP.Net Posted on : November 30, 2010 at 6:01 PM Comments : [ 0 ]

In this article we will introduce with RangeValidator control in ASP.NET using C#.

RangeValidator Example in ASP.NET using C#

RangeValidator in ASP.NET is used to check the value which is in specified range or not. If the value is not in specified range then the error message will be displayed. You can set the ErrorMessage property which you want to display for Range validator. The another property is ControlToValidate in which you can set the attached control instance. It has a type property for the data. There are the following value of type property.

1. String
2. Integer
3. Double
4. Date
5. Currency


In this example we use Integer property. The MinimumValue is 30 and the MaximumValue is 60.

RangeValidator.aspx (Design Page):

RangeValidator.aspx (source code):

<%@ Page Title="" Language="C#" MasterPageFile="~/RoseindiaMaster.master" AutoEventWireup="true"
CodeFile="RangeValidator.aspx.cs" Inherits="RangeValidator" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<div>
<h2 style="color: Green">
RangeValidator in ASP.NET 4 , C#</h2>
<strong>Age:</strong>
<br />
<asp:TextBox ID="ageTextBox" runat="server" Font-Names="Verdana" />
&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="submitButton" runat="server" Text="Submit" Width="76px" />
<br />
<asp:RangeValidator ID="RangeValidator1" runat="server" 
ErrorMessage="Enter age between 30 and 60"
ControlToValidate="ageTextBox" ForeColor="Red" MaximumValue="60" 
MinimumValue="30"
Type="Integer"></asp:RangeValidator>
</div>
</asp:Content>


Output:

Download source code
Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics