-->

Tuesday, February 10, 2015

Range ASP.NET validator control in asp.net c#

Introduction

The Range ASP.NET validator control checks whether or not the value of an input control is inside a specified range of values . It has the following four three properties:
  • ControlToValidate - Property- Contains the Input control to validate
  • MinimumValue - Property- Holds the minimum value of the valid range
  • MaximumValue - Property - Holds the maximum value of the valid range
If one of these properties is set, then the other property must also be set . Do not forget to set the Type property to the data type of the values .  The following data types can be used for the values:

String - A string data type
Integer - An integer data type
Double - A double data type
Date - A date data type
Currency- A currency data type

Application of Range ASP.NET validator control are:


  • Specify age range between the two numbers in register form
  • Use in Date of Birth selection. 
Let see the range asp.net validator control video for implementation:



Public Properties of the Range ASP.NET validator Class
MaximumValue : Obtains or sets the maximum value of the validation range for the RangeValidator control.

MinimumValue : Obtains or set the minimum value of the validation range for the RangeValidator control.

Example
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="rangevalidator.aspx.cs" Inherits="rangevalidator" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

 
 
Enter Your Age ( 18 - 30)<br />
<asp:TextBox ID="agetxt" runat="server"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="agetxt" ForeColor="Maroon" MaximumValue="30" MinimumValue="18" Type="Integer">Enter your age between 18 to 30</asp:RangeValidator>
<br />
<asp:Button ID="Button1" runat="server" Text="submit" />
<br />
   </div>
</form>
</body>
</html>
Output
range

Related Article

How to use ASP.NET validator control with example

INTRODUCTION
ASP.NET validator are controls used for validating the data entered in an input control , such as the textbox of a Web page.When a user enters invalid data in an associated control, the ASP.NET validator  control displays an error message on the screen. The error message is defined as a property value of the validation control . The data being entered is validated each time it is entered by the user , and the error message disappears only when the data is valid. Validation controls help save time and enhance the efficiency of the application by validating the data before a request is sent to the server.
The BaseValidator class
The System.Web.UI.WebControls.BaseValidator class provides basic implementation required for all validation controls.


Public Properties of the BaseValidator Class

ControlToValidate : Handles an input control, such as the TextBox Control , which needs to be validated.

Display : Handles the behavior of the error message in a validation control.

EnableClientScript : Handles a value indicating whether or not client-side validation is enabled

Enabled : Handles a value that indicates whether or not the validation control is enabled or not.

ErrorMessage : Handles the text for the error message displayed in a ValidationSummary control when validation fails.

ForeColor : Handles the color of the messgage displayed when validation fails.

IsValid : Handles a value that indicates if the focus is set on the control or not , specified by the ControlToValidate property when validation fails.

Text : Handles the text displayed in the validation control when the validation fails.

ValidationGroup : Handles the name of the validation group to which this validation control belongs.

Note: ValidationGroup property , when set, validates only the validation controls within the specified group when the control is posted back to the server.

Public Methods of the BaseValidator Class

validate() : Helps in performing validation on the associated input control and update the IsValid property

GetValidationProperty : Help in determining the validation property of a control , if it exists.

The following ASP.NET validator controls are

© Copyright 2013 Computer Programming | All Right Reserved