>>>
>>>When I set this property, I want to set all its inner controls Enabled property to the passed value.
>>
>>You can iterate over the Controls collection to do this.
>>
>>>Also can I have this as a static method in our public static class? If yes, what should I pass to this method?
>>
>>Sure. You could pass in either a UserControl, or a ControlCollection.
>>
>>
>>public static void SetEnabled(ControlCollection cc, bool enabled)
>>{
>> foreach (Control control in cc)
>> {
>> WebControl webControl = control as WebControl;
>> if (webControl != null)
>> webControl.Enabled = enabled;
>> }
>>}
>>
>>
>>This isn't recursive, but should point you in the right direction.
>
>In your function you'll need to check if webcontrol.HasControls -- if so, recursively call SetEnabled passing webcontrol.Controls
How exactly should I invoke this method?
I have user controls with
private bool editMode ;
[Description("The EditMode property is responsible for the Enabled style of the controls"), DefaultValue(true),Category("User-Defined")]
public bool EditMode
{
get { return editMode ; }
set {
editMode = value;
}
}
And I have a public static class clsEditMode where I will put the SetEnabled method.
If it's not broken, fix it until it is.
My Blog