ASP.NET has selected verification for the form input line

xiaoxiao2021-03-06  39

In ASP.NET, there is a series of verification controls that can easily verify that the data entered by the user is legal. Although these verification controls are very powerful and easy to use, they have a disadvantage, that is, usually when they use them, when submitting the web page, the user input of the entire web page is verified. In the verification control, there is no direct way to verify that some parts of the page can be validated. This article describes how to use the ASP.NET validation control and JavaScript feature to complete the functions of only the inputs of some parts of the page.

Why is sometimes it is necessary to verify the input of certain parts of the page? For example, in some applications, sometimes for the user's input is convenient, there may be a form that requires users to enter data and submitted data in the same page (this in the background management system of some information systems) , More common). And the user has an operation, such as the user enters the number of goods per purchase and submits, only needs to verify the submitted data, and other forms in the page, such as the number of shipments, because the user is not filled in Data, do not need to be verified, which also improves the efficiency of the application.

Let's take a look at how to verify the form input, first fully understand some of the attributes and usage about entering the verification control in ASP.NET.

The first introduced is the CausesValidation property. If we don't want to verify the event submitted by a button, just set the CausesValidation property to false, such as a "cancel" button, you can set this:

Another way of writing is:

Cmdcancel.causesvalidation = false;

This way, once the CausesValidation property is set to false, whether it is the client's verification or the verification of the server, it will not work.

If you want to verify some parts of the page with a selectively, you need to use some of the methods and JavaSCRPTs of the validation control, the following list, list some methods and properties in the validation control:

Name Description Page_isvalid check all the inputs in the verification page, return to the Boolean Page_Validators The array of all validation controls in the current page is a Boolean value, indicating whether the verification function is performed, and the verification function is turned off. Isvalid This property verifies whether the client's input is legal ValidatorNable (VAL, Enable) This method will use a validation control as a pass parameter, start or prohibit the control function to use the verification function, and work on the client

Special introduction to the ValidatorNable method, the method can prohibit a control to use verification functions, such as: