Validating two user controls

You can use the Validation controls to perform very different types of form validation tasks.

The advantage of writing validation logic in client-side code is that you can provide instant feedback to your users.

For example, if a user neglects to enter a value in a required form field, you can instantly display an error message without requiring a roundtrip back to the server. It looks great and creates a better overall user experience.

The problem, however, is that it does not work with all browsers.

Not all browsers support Java Script, and different versions of browsers support different versions of Java Script, so client-side validation is never guaranteed to work.

If a browser is capable of supporting Java Script, client-side validation scripts are automatically sent to the browser.

If a browser is incapable of supporting Java Script, the validation routines are automatically implemented in server-side code.

You should be warned, however, that client-side validation works only with Microsoft Internet Explorer version 4.0 and higher.

For this reason, in the past, many developers decided to add all their form validation logic exclusively to server-side code.

Because server-side code functions correctly with any browser, this course of action was safer.

Fortunately, the Validation controls discussed in this chapter do not force you to make this difficult choice.

The Validation controls automatically generate both client-side and server-side code.

Comments are closed.