Using the Validation Controls
6
Ever needed to ensure that a user typed an email address into a text box? Or
wanted to make sure that a user typed numbers only into a phone number field?
Validation involves checking that the data your applications users have entered
obeys a number of predefined rules. To help developers with the most common
data validation tasks, ASP.NET provides a set of validation controls that ease
the problems that beset web developers in the past. This chapter will show you
how to use them.
There are two kinds of form validation, differentiated by where the validation
takes place. You could write client-side JavaScript code that validates the data
typed by the user directly into the browser (client-side validation), or you could
use server-side VB or C# code to validate the user input once the form has been
submitted to the server (server-side validation).
Client-side validation has its benefits, chief among them the fact that it provides
instant feedback to users. If users fail to enter their names into a text box, the
page automatically displays an error message. The users know immediately that
they need to enter their namesthey dont need to wait for a response from the
server to tell them so. The process is quick and efficient, and good for the overall
user experience.
However, theres one big drawback with client-side validation: users must have
JavaScript enabled in their browsers, or validation simply will not occur. Some

Get Build Your Own ASP.NET 2.0 Web Site Using C# & VB, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.