TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

ASP.Net Web Form RangeValidator

ASP.Net Web Form RangeValidator with asp.net tutorial, asp.net introduction, features, project, example, server controls, labels, textbox, button, hyperlink, radiobutton, calender, checkbox, fileupload, events handling, authentication, webforms model binding, html server control, compare validdator, range validator, validation summary, mvc introduction, mvc project, view, validation, entity framework, authentication etc.

<< Back to ASP

ASP.NET RangeValidator Control

This validator evaluates the value of an input control to check that the value lies between specified ranges.

It allows us to check whether the user input is between a specified upper and lower boundary. This range can be numbers, alphabetic characters and dates.

Note: if the input control is empty, no validation will be performed.

The ControlToValidateproperty is used to specify the control to validate. The MinimumValue and MaximumValue properties are used to set minimum and maximum boundaries for the control.

RangeValidator Properties

Property Description
AccessKey It is used to set keyboard shortcut for the control.
TabIndex The tab order of the control.
BackColor It is used to set background color of the control.
BorderColor It is used to set border color of the control.
BorderWidth It is used to set width of border of the control.
Font It is used to set font for the control text.
ForeColor It is used to set color of the control text.
Text It is used to set text to be shown for the control.
ToolTip It displays the text when mouse is over the control.
Visible To set visibility of control on the form.
Height It is used to set height of the control.
Width It is used to set width of the control.
ControlToValidate It takes ID of control to validate.
ErrorMessage It is used to display error message when validation failed.
Type It is used to set datatype of the control value.
MaximumValue It is used to set upper boundary of the range.
MinimumValue It is used to set lower boundary of the range.

Example

In the following example, we are using RangeValidator to validate user input in specified range.

// RangeValidator.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RangeValidator.aspx.cs" 
Inherits="asp.netexample.RangeValidator" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
height: 82px;
        }
.auto-style2 {
width: 100%;
        }
.auto-style3 {
width: 89px;
        }
.auto-style4 {
margin-left: 80px;
        }
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="auto-style1">
<p class="auto-style4">
            Enter value between 100 and 200<br/>
</p>
<table class="auto-style2">
<tr>
<td class="auto-style3">
<asp:Label ID="Label2" runat="server" Text="Enter a value"></asp:Label>
</td>
<td>
<asp:TextBox ID="uesrInput"runat="server"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="uesrInput" 
ErrorMessage="Enter value in specified range" ForeColor="Red" MaximumValue="199" MinimumValue="101" 
SetFocusOnError="True"Type=" Integer"></asp:RangeValidator>
</td>
</tr>
<tr>
<td class="auto-style3">�</td>
<td>
<br/>
<asp:Button ID="Button2" runat="server" Text="Save"/>
</td>
</tr>
</table>
<br/>
<br/>
</div>
</form>
</body>
</html>

Output:

ASP Range 1

It throws an error message when the input is not in range.

ASP Range 2




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf