JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Creating Required Field Validators

You can see a required field validator in the ValidationControls example on the CD-ROM and in Figure 18.2 at design time. Here, I've given this control the error message "You must supply a class rank" using its ErrorMessage property. I also have set the ControlToValidate property of this control to TextBox1, the top text box in the example.

If the user doesn't enter any data into that text box and then clicks the button at the bottom of the example, which sends the page back to the server, the required field validator displays its error message and stops the page from being sent to the server, as you see in Figure 18.5. The user can enter text in the text box and try again, all without a round trip to the server.

Click To expand
Figure 18.5: Using a required field validator.

Note that validators, except for the required field validator, will validate controls that are left empty, so it's a good idea to use required field validators in addition to any other validators you use to make sure that the validation you're performing is meaningful.

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor