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:
[Html]
<Span style = "font-family: Microsoft YaHei; font-size: 16px; "> <% @ Page Language =" C # "AutoEventWireup =" true "CodeBehind =" enter a value in a specific range. aspx. cs "Inherits =" WebApplication1. enter a value in a specific range "%> www.2cto.com
 
<! DOCTYPE html>
 
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
Enter the date range from to <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 from to" 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>
</Span>

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

Please enter an integer between 0 and 100:
[Html]
<Span style = "font-family: Microsoft YaHei; font-size: 16px; "> <% @ 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; charset = 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 = "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> </span>

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



 


PS: If the input 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.