QA


Q&A

Q1:

I noticed that the Display property can have one of three settings: None, Static, and Dynamic. I understand the Static and Dynamic settings, but why on earth would anyone want to ever use the None setting?

A1:

When a validation Web control's Display property is set to None, the ErrorMessage property is never displayed, regardless of whether the data being validated is valid. It may seem confounding as to why anyone would ever want to do this.

One of the validation Web controls that we didn't discuss at length in this hour is the ValidationSummary control. This Web control lists all of the validation errors on a web page. If each validation Web control displays its error message and the ValidationSummary Web control displays each error message, each error message is displayed twice on the page. For this reason, when using the ValidationSummary Web control, some developers prefer to set the various validation Web controls' Display properties to None so that the ErrorMessage property is displayed only oncein the ValidationSummary control.

Alternatively, you can specify what message should appear in the validation control's location and what message should appear in the ValidationSummary using the ErrorMessage and Text properties of the validation controls. If a validation control has values for both its Text and ErrorMessage properties, the Text value is displayed at the validation Web control's location, while the ErrorMessage property is displayed in the ValidationSummary control (if present). So another option is to have your validation controls include a detailed error explanation in the ErrorMessage property and an abbreviated messageperhaps just an asterisk (*)for the Text property value.

Q2:

Whenever a user clicks a button, the validation controls' perform their validation logic. What if I want a Cancel button on the page or some other button that, when clicked, doesn't invoke the validation logic?

A2:

Button, LinkButton, and ImageButton Web controls all contain a CausesValidation property, which defaults to true. If you set this property to False, however, the button, when clicked, won't invoke the validation controls' validation logic.




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