Performing separate validation scenarios on the same page in Asp.Net

Hi

Earlier in asp.net 1.1 when we wanted top validate only a few fields on the click of a button and a few fields in the click of another button on the same page, there was no way to this using the validation control of Asp.Net.

In Asp.Net 2.0 this problem is solved. Now when we want to perform separate validation scenarios on the same page we can use the validationGroup property. With the help of this property we can group the validation control and then tell the post back control to validate a particular group only.

This is very useful for the editing scenarios of the data controls. We need to set the ValidationGroup property to the same value for all the validators that belong to a particular group. On the button control or the postback control (with causes validation property set to true) set the validationGroup property to the name of the group that the control needs to validate when there is a postback.

By default all the validation control have same group "". In the server side we also have a Validate(“NameOfGroup”) method to validate a particular group only. We can use the GetValidators("NameOfGroup") to get a collection of validators in the given group.

[Note: Page.IsValid reflects validity of all controls (cumulative) that have had Validate called]

Hope this Helps
Thanks
Vikram


Share this post   Email it

Feedback

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 

Copyright © 2006 - 2012 Vikram Lakhotia