Application background
1. When the user needs to fill out the form.
2. The page uses server validation controls.
3. By the user to choose whether to fill out more items, more items display and hidden with display control, the following figure.
Click "Add Service Content" to display the new form item, as shown below.
Click "Cancel Add" to hide the new form item.
Problem: When the user clicks Next, does not validate the new area form of Display=none, when the user clicks "Cancel increases", disables the server validation control. Instead, enable the server validation control.
Solving method
Let's use jquery to get it done, mostly too.
1. Output the validation control to be disabled.
Copy Code code as follows:
var validatorcontrols = new Array (' Requiredfieldvalidatorname ', ' Requiredfieldvalidatorid ');
2. Disable validation by default.
Copy Code code as follows:
for (var i = 0; i < validatorcontrols.length i + +) {validatorenable ($ (' # ' + validatorcontrols[i]). Get (0), false);
3. When you click "Add Service Content", enable authentication.
Copy Code code as follows:
for (var i = 0; i < validatorcontrols.length i + +) {validatorenable ($ (' # ' + validatorcontrols[i]). Get (0), true);
4. It's done.
Summary
In fact, the core of the validatorenable () is the function. Sometimes looking at the examples may not really understand, only the real hands-on ability to have a more profound impression.