Validation controls are used to validate user input, and these controls enable developers to easily validate user input. Asp. NET provides six kinds of validation controls.
1.Required Field Validator: Controls that verify that the input is empty.
Main properties:
Controls to Validate: Represents the ID of the control that is to be checked. This property must be set to the ID of the input control, otherwise an exception will occur. In addition, the control represented by this ID must be in the same container as the validation control.
Error message: Indicates the information that occurred when the detection was illegal.
Display: Indicates how the error is displayed, with the values static, dynamic, and none. Static indicates that the error message for the control (the errors messages) occupies a fixed position on the page, and that if there is no error, his display is similar to that of the label;dynamic indicating that the control's error message appears, and none indicates that the control's error message appears. However, it can be displayed in validator summary.
2.Range Validator: Range validation control.
Tests whether the value of an input is within a specified range. In addition to the same properties as the required Field validator, there are:
Maximum Value Range Maximum
Minimum Value Range Minimum
Tyep the data type of the input value.
3.Compare Validator: Compare validation controls.
Used to compare a user's input to the value or constant of another control on a Web form.
Basic properties:
Controls to Validate: The control ID to be validated;
Value to Compare: The constant value used to compare;
Controls to Compare: The control ID used to compare;
Type: The data type of the comparison;
Operator: Compare the operation type;
Operator has 7 optional attribute values, as detailed in the following table:
value |
Description |
Equal |
The comparison of the two values is equal, through validation. |
Not Equal |
The two values compared are not equal, through validation. |
GreaterThan |
Validation is passed when the value that is validated (the value of the control to validate property points to the controls) is greater than the specified constant (value to Compare) or the specified control (controls to Compare) value. |
Greater Than Equal |
Validation passes when the value that is validated (the value of the control to validate property points to the controls) is greater than the value equal to the specified constant (value to Compare) or the specified control (controls to Compare). |
less Than |
validation passes when the validated value (the value of the ControlToValidate property points to the control) is less than the specified constant (valuetocompare) or the value of the specified control (controltocompare). |
less Than Equal |
Validation is passed when the value that is validated (the value of the control to validate property points to the controls) is less than the value of the specified constant (value to Compare) or the specified control (controls to Compare). |
Data Type Check |
Validation is passed when the value that is validated (the value of the control to validate property is pointed to) is the same as the value type of the specified constant (value to Compare) or the specified control. |
4.RegularExpressionValidator: Regular expression validation control.
Provides a regular expression editor, validationexpression in the Properties window. Use this control to verify format strings such as email, id number, URL, and so on.
5.Custom Validator: User-defined validation control.
The on Server Validate event is a user-defined validation function in the form of the following:
protected void Custom Validator1_server Validate (object source, Server Validate Event Args Args)
{
}
If args. Is valid=true means validation passed, otherwise the validation fails.
6.Validation Summary: summary display validation control.
Several noteworthy properties:
Header text: Validates the text displayed in the title section of the summary page.
Show Summary: Lets you specify whether a summary is displayed on the page.
Show Messages Box: Specifies whether to display a message dialog box to display the summary information for the validation.
Display mode: A pattern for setting the validation summary display, preferably with the following values:
Bullet List: Default display mode, each error message appears as a separate item;
List: Each display information is displayed in the peer;
Single Paragraph: All error messages are displayed in the same paragraph.
7. Shielding Verification function
In general, ASP. NET validation will automatically open the validation function, when the user submits, if the validation does not pass, then the data can not be submitted. But sometimes it is necessary to allow users to send data even if they are not authenticated. For example, clicking the Cancel button does not require that all data be validated to submit data.
In this case, in order to mask server side and client validation against a control, you can use the following two methods to send data without triggering a validation control.
1 set the control's CausesValidation property to False. For example, create a Cancel button so that it does not trigger validation checks.
2 If you want to mask client-side validation and perform only server-end validation, you can set this validation control to not generate client-side scripting, and you can set the Enable client Script property of the control to False if you want to execute some of the Serverõs code before validation.