Chapter 2. Using Validation Controls

In This Chapter

Using validation controls to validate user input

Working with advanced validation controls

Adding a validation summary to a page

Validating more than one group of input fields

Validation is one of the most important parts of any type of computer programming. The moment you expose your program to the outside world by asking a user to input some data, the possibility arises that the user will enter the wrong data, or that the user will forget to enter any data at all. To get any real work done, ASP.NET programs need to protect themselves from such errors and omissions.

You won’t be able to catch all the errors a user might make. For example, a user might spell his or her name wrong (due to a bad day, lack of coffee, or whatever). But you can detect and prevent common types of errors. For example, you can require that the user enter some data into a text box — and, if the text box is supposed to contain a number, you can require that the user enter a valid number. This chapter shows how to do that and more.

Using Validation Controls

All code listings used in this book are available for download at www.dummies.com/go/aspnetaiofd.

Validating the Hard Way

In Book 1, I present a simple calculator program that added two numbers entered by the user. In real-world terms, that program is a little too simple; it didn’t include any validation code. It would crash if the user ...

Get ASP.NET 2.0 All-In-One Desk Reference For Dummies® 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.