JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Required Field Validators

The simplest validation control is the RequiredFieldValidator control, which simply makes sure that the users have entered data into a data-entry control. For example, you may want to make sure that the users enter the number of shoes they want to buy. If they omit to enter a value, this validation control will display its error message.

This control has a property named InitialValue, set to an empty string ("") by default. If the data has not changed from that value when validation occurs, the control displays its error message. The required field validator in the ValidationControls example makes sure that the user has entered a class rank in the top text box you see in Figure 18.1.


Here's a little known fact that can save you some frustration: If a data-entry control is empty, no validation is performed by any of the validation controls except for required field validators, and by default, that means that validation succeeds. To avoid this problem, you should use a required field validator to make sure the user enters data into the data-entry control before checking that data.

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor