Sunday, October 22, 2006

Validation groups on a page

In ASP.NET1.x controls on a single page are validated together! If you had 2 buttons on a page that were technically not related, example is a page that has a "microsoft search" button and a "save cart" button, then if there was a RequiredFieldValidator on a textbox related to the "save cart" button clicking "google search" will also be invalidated as both buttons are part of the same invalidation group.

ASP.NET2.0 allows controls in a page to be grouped logically so that postback in one group is not dependent on another!


Each button will now have a new attribute called ValidationGroup

The RequireFieldValidator will also have this attribute which signifies what group it belongs to!

A new feature of the RequireFieldValidator is the SetFocusOnError attribute. It will set the focus of the page to the ControlToValidate when the error occurs!


asp:requiredfieldvalidator id="RequiredFieldValidator1" errormessage="Required Field Validator Error" ControlToValidate="txtAge" ValidationGroup="groupOfControls" SetFocusOnError="True"

No comments: