rty, which you check in server code to determine if all of the user input is OK.
Most Web sites do all of their validation checks on the server. You need to write the server-based checks anyway for clients without script, so it can be hard to justify writing it all over again for rich clients.
Validation controls change all that, because almost all the duplicated logic is encapsulated in the controls. If a client with Internet Explorer 4.0 or later uses your page, it can do the same input validation that takes place on the server without you having to write any special client script.
The client side validation has a number of features:
In order to use validators effectively, it helps to have a firm definition of what they are. Let's refine our previous definition a little:
"A validator is a control that checks one input control for a specific type of error condition and displays a description of that problem."
This is an important definition, because it means that you frequently need to use more than one validator control for each input control.
For example, if you want to check whether or not user input in a text box is (a) nonblank, (b) a valid date between a particular range and (c) less than the date in another text input control, you would want to use three validators. While this might seem cumbersome, remember that to be helpful to the user, you would want to have three different text descriptions for all these cases.
The different types of validators are listed as follows:RequiredFieldValidatorChecks that the user has entered or selected anything.
Client Features
Most Web sites do all of their validation checks on the server. You need to write the server-based checks anyway for clients without script, so it can be hard to justify writing it all over again for rich clients.
Validation controls change all that, because almost all the duplicated logic is encapsulated in the controls. If a client with Internet Explorer 4.0 or later uses your page, it can do the same input validation that takes place on the server without you having to write any special client script.
The client side validation has a number of features:
- Errors can appear and disappear immediately after the bad input is entered/corrected. This immediate feedback makes it much easier to correct bad input.
- Post-back is prevented if there are errors that are detectable on the client, saving the user time and reduces hits on the server.
- The ValidationSummary updates itself without posting back if it detects errors.
- The ValidationSummary can optionally display a message box to the user if there are errors.
- The client logic is all contained in a JScript library, so no ActiveX components or Java applets are used.
- Can optionally use VBScript to perform checks involving localized date and number comparison.
- An object model is exposed on the client to allow enhancement of client-side validation and behavior.
What is a Validator?
In order to use validators effectively, it helps to have a firm definition of what they are. Let's refine our previous definition a little:
"A validator is a control that checks one input control for a specific type of error condition and displays a description of that problem."
This is an important definition, because it means that you frequently need to use more than one validator control for each input control.
For example, if you want to check whether or not user input in a text box is (a) nonblank, (b) a valid date between a particular range and (c) less than the date in another text input control, you would want to use three validators. While this might seem cumbersome, remember that to be helpful to the user, you would want to have three different text descriptions for all these cases.
The different types of validators are listed as follows:RequiredFieldValidatorChecks that the user has entered or selected anything.
| 对此文章发表了评论 |

