RangeValidator example in Asp.Net

InfoPath alternatives for form designing SharePoint

In this post we will see an example of how to use RangeValidator in Asp.Net.

There are different types of validation controls are provided by Asp.Net. Check this article for more information.

You can also check my previous post on RequiredFieldValidator example in Asp.Net.

– RangeValidator: Here validation succeeds if the input control contains a value within a specific numeric, alphabetic, or date range.

– To use RangeValidator, drag and drop a RangeValidator from Toolbox.

Below are the property need to set:
ControlToValidate: This property field needs to be set as on which field you want to validate.

ErrorMessage: This property will show what ever error message you will give.

MaximumValue: Indicates what will be the maximum value allowed.

MinimumValue: Indicates what will be the menimum value allowed.

Type: Indicates what will be the type. The value can be Integer, Currency, Date, Double or String.

Below is the full HTML code

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”ValidatorExamples.aspx.cs”
Inherits=”ValidatorExamples” %>

<!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 runat=”server”>
<title>RangeValidator example in Asp.Net</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
Enter Age:<asp:TextBox ID=”txtAge” runat=”server”></asp:TextBox>
<br />
<asp:RangeValidator ID=”RangeValidator1″ runat=”server” ErrorMessage=”Age should be between 10 to 90!”
ForeColor=”Red” ControlToValidate=”txtAge” MaximumValue=”90″ MinimumValue=”10″
Type=”Integer”></asp:RangeValidator>
<br />
<asp:Button ID=”btnSubmit” runat=”server” Text=”Submit” />
</div>
</form>
</body>
</html>

If you try to submit enter any value in the Textbox which is not between the menimun value and maximum value set then you will get the error message as shown in the figure below:

Similar SharePoint 2013 Tutorials


About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →

Leave a Reply