ASP.NET 2.0 - Validation Groups and Cross-Page Posting

本文介绍ASP.NET中使用ValidationGroup属性进行验证控制及跨页回发(PostBack)的技术。通过设置ValidationGroup可以指定验证部分页面元素,而跨页回发则允许将数据从一个网页传递到另一个网页进行处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 1. Validation Groups

In ASP.NET 2.0, there is a new property called the ValidationGroup that can be assigned a string to specify a section. This property exists on the validation controls and on the controls that cause PostBacks to occur. When a control performs a PostBack, the validator controls that have a matching ValidationGroup property are validated.

On PostBack, the IsValid property on the Page object only reflects the validity of the validation
controls that have been validated. By default, these are the validation controls that are in the same ValidationGroup, but you can call a validation control’s Validate method to add that control to the set of controls that the IsValid reports on.

2. Cross-Page Posting

Cross-page posting is frequently desired in a scenario where data is collected on one Web page and processed on another Web page that displays the results. In this scenario,
a Button control has its PostBackUrl property set to the Web page to post back to. In the processing page, which is the Web page that you post back to, the data from the first Web page is available.

The processing page typically needs to access the data from the first page, which is possible by using the PreviousPage property of the Page object. The PreviousPage property
is set if you are cross-page posting, and if the PreviousPage is set to Nothing (C# null), no cross-page posting occurs.

You can access any of the controls in the previous page by using the FindControl method on the NamingContainer of the control that you are trying to locate.

Another way to access the previous page data is to create public properties that expose the data that you need to access. After creating public properties, you need to set the PreviousPageType directive on the result page.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值