Hour 12. Validating User Input with Validation Controls


In this hour, we will cover

  • The various classes of input validation

  • How to use the RequiredFieldValidator to ensure that the user has provided input

  • How to use the CompareValidator

  • How to ensure that the user's input falls between a range of values by using the RangeValidator

  • How to use the RegularExpressionValidator

  • The aesthetic properties of the validation Web controls

As we have examined in previous hours, collecting user input through an ASP.NET page is a relatively easy task. Unfortunately, when we're collecting a user's input, there is no guarantee that he has provided the desired input in an acceptable format. That is, imagine that you are asking the user to specify his weight, much like we did with the BMI calculator a few hours ago. What should happen if, for weight, the user enters something like "Far too much"?

Ensuring that user input is in a proper format is a technique known as input validation and is the topic for this hour. If you have had experience with other dynamic web page creation technologies, such as ASP, PHP, or JSP, you likely are more than familiar with input validation. Performing input validation in these older technologies was a real headache.

Fortunately, ASP.NET makes input validation a breeze with the help of validation controls, which are Web controls designed to do nothing else but perform input validation. We will examine how to use four validation controls in this hour: the RequiredFieldValidator, the CompareValidator, the RangeValidator, and the RegularExpressionValidator.




Sams Teach Yourself ASP. NET 2.0 in 24 Hours, Complete Starter Kit
Sams Teach Yourself ASP.NET 2.0 in 24 Hours, Complete Starter Kit
ISBN: 0672327384
EAN: 2147483647
Year: 2004
Pages: 233

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net