Result of Special Case verification for ASP. NET-Asp. NET Server controls

Source: Internet
Author: User

Verification ensures that user input meets your specified conditions. In most cases, this operation is relatively simple. However, input validation sometimes introduces special conditions. It is important to understand what these conditions are, how the verification is executed, and what possible verification results are.

 

I. Comparison with blank fields

If the field is blank, all verification controls except the requiredfieldvalidator control regard this field as a valid field. You must use the requiredfieldvalidator control to avoid blank fields. For example, if you attach the rangevalidator control to a date field, the verification is successful when you enter a date within the specified range or leave this field blank. To ensure that you enter a date, you must add the requiredfieldvalidator control to the date field in addition to the range check.

 

2. Comparison with other controls

When using the comparevalidator control, you can specify to verify against the value of another control. For example, you have two fields for entering the date, one for the start date and the other for the end date. Use the comparevalidator control to ensure that the start date is earlier than or equal to the end date.

Security Description: user input on ASP. NET may include malicious client scripts. By default, this page verifies that user input does not include script or HTML elements.

If the verification control cannot parse the values in another control, they usually do not cause errors. Instead, they pass the verification check. This happens if values in other controls are missing or cannot be converted to the Data Type of the comparevalidator control.

 

Specific tests executed by these controls and possible results are as follows:

· If the target control entered in the controltovalidate attribute of the Start Control has no value, the isvalid attribute is deemed to be true and the verification is successful.

· If the target control value in the controltovalidate attribute cannot be converted to an appropriate data type, isvalid is treated as false.

· If the target control value in the controltocompare attribute cannot be converted to an appropriate data type, isvalid is considered as true.

· Finally, if all these tests have passed, both controls are non-empty and can be converted to data types. Therefore, the controls perform Actual comparisons and set isvalid accordingly.

 

This policy prevents multiple errors from being reported for the same invalid input. The verification control is designed to test and report only one value and display messages as accurately as possible when an error occurs.

For example, in the end date example, assume that the user enters an invalid start date. The user then enters the end date. During verification check (usually on the server), the same error date may cause errors in both the start date field and end date field. To avoid this, end date verification (dependent on another field verification) will not cause errors.

Therefore, you must ensure that each individual field is fully verified. In this example, you will make sure that you have entered the correct date in the start date field. In many cases, you should use the requiredfieldvalidator control together with the verification control that tests specific input content. In some cases, the comparevalidator control that sets the operator attribute to datatypecheck is also useful. It performs a simple type check instead of comparing it with another value or control.

Related Article

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.