Rangevalidator for ASP. NET verification controls

Source: Internet
Author: User

The rangevalidator control is used to check whether the user input value is between two values. You can compare different types of values, such as numbers, dates, and characters. We generally use it to verify the input age or test score.

Let's take a look at the attributes of rangevalidator:

Attribute

Description

 Backcolor

Background Color

 Controltovalidate

ID of the verified Control

 Display

Verify the display behavior of the control.

Valid values include:

· None-verification messages are never displayed inline.

· Static-allocate space in the page layout for displaying verification messages.

· Dynamic-If verification fails, the space used to display verification messages is dynamically added to the page.

 Enableclientscript

Boolean value that specifies whether to enable client verification. True indicates enabled, and false indicates disabled.

 Enabled

Boolean value that specifies whether to enable the verification control. True indicates enabled, and false indicates disabled.

Errormessage

Text displayed in the validationsummary control when verification fails.

Note: If the text property is not set, the text is displayed in the verification control.

 Forecolor

The foreground color of the widget. That is, the font color of the error message.

 ID

The unique ID of the control.

 Isvalid

Boolean value indicating whether the input control specified by controltovalidate has passed verification. True indicates pass, and false indicates no pass.

 Maximumvalue

Specifies the maximum value of the input control.

 Minimumvalue

Specifies the minimum value of the input control.

 Runat

Specifies that the control is a server control. Must be set to "server ".

 Type

Specifies the Data Type of the value to be checked. Types:

· Currency

· Date

· Double

· Integer

· String

 Text

Message displayed when verification fails.

The following are two small instances:

Enter the date range from

 

<%  @ Page Language  =  "  C #  "  Autoeventwireup  =  "  True  "  Codebehind =  "  Enter a value in a specific range. aspx. CS  "  Inherits  =  "  Webapplication1. enter a value in a specific range.  "   %>  <!  Doctype html >  <  Html  Xmlns  = "Http://www.w3.org/1999/xhtml"  >  <  Head  Runat  = "Server"  >  <  Meta  HTTP-equiv  = "Content-Type"  Content = "Text/html; charsets = UTF-8"  />      <  Title  > </  Title  >  </  Head  >  <  Body  >      <  Form  ID  = "Form1" Runat  = "Server"  >  Enter the date range from  <  BR  />          <  BR  />  Date:  <  ASP: textbox  ID  = "Date"  Runat = "Server"  > </  ASP: textbox  >          <  ASP: rangevalidator  Type  = "Date"  ID  = "Rangevalidator1"  Forecolor  = "Red"  Runat  = "Server"  Errormessage  = "Enter the date range from" Maximumvalue  = "2012-12-31"  Minimumvalue  = "2012-01-01"  Controltovalidate  = "Date"  > </  ASP: rangevalidator  >                   <  P  >              <  ASP: button  ID  = "Button1" Runat  = "Server"  Text  = "Submit"   />          </  P  >      </  Form  >  </  Body  >  </  Html  > 

 

 

 

 
 

 
 

If the entered content is not a specified date, an error message is displayed.

 

Please enter an integer between 0 and 100:

 

 

 <%  @ Page Language  =  "  C #  "  Autoeventwireup =  "  True  "  Codebehind  =  "  Enter a value in a specific range. aspx. CS  "  Inherits  =  " Webapplication1. enter a value in a specific range.  "   %>  <!  Doctype html  >  <  Html  Xmlns  = "Http://www.w3.org/1999/xhtml"  >  <  Head  Runat  = "Server" >  <  Meta  HTTP-equiv  = "Content-Type"  Content  = "Text/html; charsets = UTF-8"  />      <  Title  > </  Title  >  </  Head  >  < Body  >      <  Form  ID  = "Form1"  Runat  = "Server"  >  Enter an integer between 0 and 100.  <  BR  />          <  BR  />  Date: <  ASP: textbox  ID  = "Txtnum"  Runat  = "Server"  > </  ASP: textbox  >          <  ASP: rangevalidator  Type  = "Integer"  ID  = "Rangevalidator1"  Forecolor = "Red"  Runat  = "Server"  Errormessage  = "Please enter an integer between 0 and 100"  Maximumvalue  = "2012-12-31"  Minimumvalue  = "2012-01-01"  Controltovalidate  = "Txtnum"  > </  ASP: rangevalidator  >                   <  P >              <  ASP: button  ID  = "Btnsubmit"  Runat  = "Server"  Text  = "Submit"   />          </  P  >      </  Form  >  </ Body  >  </  Html  > 

 

 

 

 

If the input content is not an integer between 0 and 100, an error message is displayed.

If the entered content is empty or all are spaces, no error message is displayed. We can use other controls, such as requiredfieldvalidator, to change the input box to a required field.

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.