13.07.2015 Views

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9: Validation Controls 217While client-side validation is more practical because the validation process isdistributed to the clients, it does not offer the level of protection provided by the server.Clients can get around client-side validation. For example, you would not want credit-cardvalidation done on the client-side even though you could design an application that coulddo so. So while some client-side validation with <strong>ASP</strong>.<strong>NET</strong> is possible, especially usingMicrosoft’s Internet Explorer, even validated data are re-validated on the server side.Types of Validation<strong>ASP</strong>.<strong>NET</strong> <strong>3.5</strong> has five validation controls and a validation summary control. TheToolbox Validation menu displays all of the validation controls. Each can be draggedinto the Visual Studio 2008 editor in the same way as the other controls. The followingsummarizes the controls in the order you will find them in the Validation menu:RequiredFieldValidatorRangeValidatorRegularExpressionValidatorCompareValidatorCustomValidatorValidationSummaryChecks to make sure specified field is filled inChecks to see if entry is within specified rangeUses regular expressions to evaluate entryCompares entry with other entry fieldsUser-developed C# method to evaluate entered dataSummarizes page validationWhen you use these controls, use either the Split or Design mode. The validationcontrols generate error messages, and the space where that message appears is visiblein the Design view. Basically, the Design mode shows what you will see if every singleerror message from a failed validation appears. As with other controls, you can use theProperties window to set values for the different properties. If you prefer, you can code inthe values for the available properties just as you would any other control.In the next several sections, you will see how to use the five different Validatorcontrols. Each of the controls has a specific use, and by looking at each, you candistinguish which is the most appropriate for a specific task. For example, you maywant to be sure that users fill in a form requesting their last name. Because of the rangeof last names, including ones with hyphens, looking for anything precise to ensurethat the name is entered correctly is virtually impossible. Such a form only requires aRequiredFieldValidator that makes sure the field is <strong>com</strong>pleted. Conversely,even though email addresses are diverse, they all have certain features that must beincluded for them to be valid. For example, all emails have an @ symbol. If the @symbol is missing from an entry, a validator that checks to see if the field is <strong>com</strong>pleted

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!