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 241shows that the CustomValidator does not throw an error, but the validation method(IsValid) can be used to generate C# messages.With the CustomValidator control, the scope of validation events is limitless. Evenwith validators such as the RegularExpressionValidator that can have any number ofdifferent regular expressions used in the validation process, you still need a validatoroption where you can validate anything you want. Chances are, though, that most ofthe validation work you do will be with one of the simpler validation controls. However,the CustomValidator control is there when you need it.Summarizing Validation ErrorsAs you have seen in the discussion of validation, wherever you have an error message,the space taken up by the message leaves a gap. With several different controls usingsome kind of validation control, a page could get cluttered and messy very quickly. Aneasy way to prevent this state of affairs is to use the ValidationSummary control. Withthis control all of the error messages for the page are stored in one place. The kind ofmessage and validation control can be any you want. However, instead of the errormessage displayed in the location where you placed the validation control, all ofthe errors are displayed together. Usually, the summary errors are placed at the endof the form.To see how this works, an application using two TextBox controls with aRequiredFieldValidator control and a RegularExpressionValidator control are set upas they have been in previous examples with one important difference—their Displayproperty is set to None. When the display setting is None, the validation controls stillshow up in the Design mode as taking up space as shown in Figure 9-13. However, as youcan see in Figures 9-14 and 9-15, no space at all is taken up by the area reserved for errormessages. Instead, all of the messages appear at the bottom where the ValidationSummarycontrol is positioned.The example is easy to try. Just put in the controls and labels as shown in Figure 9-13.Where you see the bullet list of error messages is in the ValidationSummary control. Addthe error messages to the two controls and controls to validate, and set the RegularExpressionValidator control’s ValidationExpression to “email”. Remember to also setthe display of both validators to “None”. When you place the ValidationSummary

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

Saved successfully!

Ooh no, something went wrong!