Summarizing Validation Messages

ASP.NET中ValidationSummary控件的使用
ASP.NET的ValidationSummary控件可将所有验证消息集中显示,节省页面空间。添加该控件很简单,只需将其放置在页面上,它会自动收集各验证控件的错误消息。还可设置Text属性,修改显示内容。此外,可通过DisplayMode和ShowMessageBox属性调整布局和行为。
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.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值