Summarizing Validation Messages

王朝asp·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

Summarizing Validation Messages

As you may have noticed, all the validation messages take up a lot of space

on the page梱ou may not want to sacrifice all that space for your

validation messages. ASP.NET provides its ValidationSummary control so that

you can display all the validation messages in one place as well as display

either nothing at all or a simple indicator next to each invalid control.

The sample page, shown in Figure 8.3, displays an asterisk next to each

invalid control and full error message text in the summary.

Figure 8.3. The ValidationSummary control lists all the ErrorMessage

properties for invalid controls in one place.

Adding the ValidationSummary control is simple: All you have to do is place

the control on your page. It automatically seeks out all the various

validation controls on the page, gathering the ErrorMessage property from

each control as necessary.

To set the text to be displayed within the validation controls themselves,

set the Text property for each control. This property overrides the

ErrorMessage property, and each control uses the Text property to determine

what to show within its own display. (If you don't specify the Text

property, as has been the case throughout this chapter, the controls

display their ErrorMessage property.) To add the ValidationSummary control

to your page, follow these steps:

Select the first validation control on the page and then Shift+click each

of the remaining validation controls, selecting them all.

In the Properties window, set the Text property (for all the selected

controls) to *.

Click directly above the Save button to place the insertion point within

the page. In the Toolbox window, double-click the ValidationSummary control

to insert an instance of this control.

Browse the page and then click Save without entering any data. Try entering

invalid data in some of the controls. When you submit the page, you should

see asterisks next to the invalid controls and a summary of the errors at

the bottom of the page.

TIP

If you want to modify the layout and behavior of the ValidationSummary

control, check out the DisplayMode property, which can be set to List,

BulletList, or Paragraph. Try them all to see how they affect the display.

In addition, you might check out the ShowMessageBox property, which allows

you to have up-level browsers (such as Internet Explorer) display a message

box alert containing the validation information.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航