ASP. NET validation control

Source: Internet
Author: User
Tags unique id

First, RequiredFieldValidator

Description: Makes an associated input control a required field.

A feature RequiredFieldValidator control that is commonly used to verify that the text input box is empty. When a user submits data from a Web page to the server side, the system automatically checks whether the input of the control being validated is empty, and if it is empty, the RequiredFieldValidator control displays a hint in the Web page.

Example:

<asp:requiredfieldvalidator id= "RequiredFieldValidator1" runat= "Server" controltovalidate= "Txtname" Errormessage= "Please enter your name! "></asp:RequiredFieldValidator>

tr>
Properties
description
controltovalidate
This property gets or sets the input to validate Control
display
This property gets or sets the display behavior of the error message in the validation control
enableviews Tate
This property gets or sets a value that indicates whether the server control maintains its own view state and the view state of any child controls it contains to the client that made the request
Errormessag E
This property gets or sets the text of the error message displayed in the ValidationSummary control when validation fails
ForeColor
the genus Sex Gets or sets the color of messages displayed after validation fails
IsValid
This property gets or sets a value that indicates whether the associated input control passes validation
setfocusonerror
This property gets or sets a value that indicates whether the focus is set to the control specified by the ControlToValidate property when validation fails
text
This property gets or sets the text that is displayed in the validation control when validation fails
Page
This property gets the server control that contains the Reference to page instance
Visible
This property gets or sets a value that indicates whether the server control is rendered as UI on the page

Second, CompareValidator

Description: Compares the value of a user input control to a value entered into another space or to a Changshu value

The CompareValidator control, also known as a comparison validation control, is primarily used to compare the value of an input control to a specified constant value or other input control by a specified comparison operator (>, <, =, <>, >=, and <=, and so on). To determine whether a two value matches. In addition, the CompareValidator control can be used to determine whether a user-entered value can be converted to the data type specified by its Type property.

Example:

<asp:comparevalidator id= "CompareValidator1" runat= "Server" controltocompare= "Txta" controltovalidate= "TXTB" Errormessage= "value must be greater than B value" ></asp:CompareValidator>

Property Describe
BackColor The background color of the CompareValidator control.
ControlToCompare The input control to compare with the input control being validated.
ControlToValidate The ID of the input control to validate.
Display

Validates the display behavior of the error message in the control.

The legal values are:

  • None validation messages are never displayed inline.
  • Static allocates space in the page layout to display validation messages.
  • Dynamic if validation fails, the space used to display the validation message is dynamically added to the page.
EnableClientScript Boolean value that specifies whether client-side validation is enabled.
Enabled A Boolean value that specifies whether the validation control is enabled.
ErrorMessage

The text that is displayed in the ValidationSummary control when validation fails.

Note: If the Text property is not set, it will be displayed in the validation control.

ForeColor The foreground color of the control.
Id The unique ID of the control.
IsValid A Boolean value that indicates whether the input control specified by ControlToValidate is validated.
Operator

The type of comparison operation to perform.

The operators are:

  • Equal
  • GreaterThan
  • Greaterthanequal
  • LessThan
  • Lessthanequal
  • NotEqual
  • DataTypeCheck
Runat Specifies that the control is a server control. Must be set to "server".
Text The message that is displayed when validation fails.
Type

Specifies the data type of the value to be compared.

Types are:

  • Currency
  • Date
  • Double
  • Integer
  • String
ValueToCompare A constant value to compare to the value entered by the user into the validated input control.

Third, RangeValidator

Description: Checks whether the value of the input control is within the specified range

Example:

1 <asp:RangeValidator ID="RangeValidator3"runat="server" ControlToValidate="txtAge" ErrorMessage="RangeValidator" MaximumValue="60"MinimumValue="18"></asp:RangeValidator>

  

Properties Description
BackColor RangeValidator the background color of the control
ControlToValidate The ID of the control to validate
Display Validates the display behavior of the control.

The valid values are:

  • None-Verify that messages are never displayed inline.
  • Static-Allocates space in the page layout to display the validation message.
  • dynamic-if validation fails, the space used to display the validation message is dynamically added to the page.
EnableClientScript Boolean value that specifies whether client-side validation is enabled.
Enabled A Boolean value that specifies whether the validation control is enabled.
ErrorMessage

The text that is displayed in the ValidationSummary control when validation fails.

Note: If you do not set the Text property, it will also appear in the validation control.

ForeColor The foreground color of the control.
Id The unique ID of the control.
IsValid A Boolean value that indicates whether the associated input control passed validation.
MaximumValue Specifies the maximum value of the input control.
MinimumValue Specifies the minimum value for 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 detected. Types are:

  • Currency
  • Date
  • Double
  • Integer
  • String
Text The message that is displayed when validation fails.

Iv. RegularExpressionValidator

Description: Used to verify that the input value matches the pattern specified by the regular expression.

Example:

<asp:regularexpressionvalidator id= "RegularExpressionValidator1" runat= "Server" controltovalidate= "Txtemail" Errormessage= "Mailbox format is incorrect" validationexpression= "\w+ ([-+. '] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) * "></asp:RegularExpressionValidator>

Properties Description
BackColor RangeValidator the background color of the control
ControlToValidate The ID of the control to validate
Display Validates the display behavior of the control.

The valid values are:

  • None-Verify that messages are never displayed inline.
  • Static-Allocates space in the page layout to display the validation message.
  • dynamic-if validation fails, the space used to display the validation message is dynamically added to the page.
EnableClientScript Boolean value that specifies whether client-side validation is enabled.
Enabled A Boolean value that specifies whether the validation control is enabled.
ErrorMessage

The text that is displayed in the ValidationSummary control when validation fails.

Note: If you do not set the Text property, it will also appear in the validation control.

ForeColor The foreground color of the control.
Id The unique ID of the control.
IsValid A Boolean value that indicates whether the associated input control passed validation.
Runat Specifies that the control is a server control. Must be set to "server".
Text The message that is displayed when validation fails.
ValidationExpression Specifies the regular expression that validates the input control. On both the client and the server, the syntax of the expression is different.

Wu, CustomValidator

Description: User-defined validation can be performed on the input control.

Example:

Liu, ValidationSummary

Description: Used to display a summary of all validation errors inline in a Web page, message box, or both.

Example:

1 <asp:ValidationSummary ID="ValidationSummary1"runat="server" HeaderText="发生了以下错误:"/>

  

Properties Description
DisplayMode

How to display the summary. Valid values are:

  • BulletList
  • List
  • Singleparagraph
EnableClientScript Boolean value that specifies whether client-side validation is enabled.
Enabled A Boolean value that specifies whether the validation control is enabled.
ForeColor The foreground color of the control.
HeaderText The caption text in the ValidationSummary control.
Id The unique ID of the control.
Runat Specifies that the control is a server control. Must be set to "server".
ShowMessageBox A Boolean value that indicates whether the validation summary is displayed in a message box.
ShowSummary Boolean value that specifies whether the validation summary is displayed.

ASP. NET validation control

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.