Wednesday, November 17, 2004

VJs Tip Of The Day - November 17th 2004

Whidbey Days - Page.GetValidators method

Yesterday we talked about ValidationGroups now here is an application of the same... System.Web.UI.Page has now got GetValidators method... The signature of the method looks like below...

public ValidatorCollection GetValidators(string validationGroup)

Basically System.Web.UI.Page has got a property called "Validators"... This property was always there and it use to return back all the validators of a page... This property will ofcourse exist for Whidbey too but now this special method adds extra value...

As the signature indicates the GetValidators method will accept a string which will be validationGroup name which you have given to your validation controls and give you back a strongly typed collection of Validator Controls... If you do not pass the string name of validation group here it will return back the default validation group... This would be the same group which will be given by the Validators property...

I would recommend using this method as you would have a generic way of accessing the validators and if the group name is passed dynamically your page logic will work in both the cases...

PS: An easy way to find out how important you are to someone is to find out whether your contact number is stored in the phone book of that person... If someone does not care to store your number with them somewhere then PROBABLY he/she is not dependant on you in anyways...



No comments: