65.9K
CodeProject is changing. Read more.
Home

Disable Child Controls Recursively

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

Nov 2, 2010

CPOL
viewsIcon

10240

You can just use "not IsDisable" versus the IF...ELSE block. Additionally, the recursive call to ControlStatus should be done all the time so that the parent control is enabled/disabled along with the children. // to enable\disable the control & its child controls public...

You can just use "not IsDisable" versus the IF...ELSE block. Additionally, the recursive call to ControlStatus should be done all the time so that the parent control is enabled/disabled along with the children.
        // to enable\disable the control & its child controls
        public void ControlStatus(Control control, bool isDisable)
        {
            foreach (Control c in control.Controls)
                try
                {
                    if (c is WebControl)
                        ((WebControl)c).Enabled = !isDisable;

                    if (c.HasChildren)
                        ControlStatus(c, isDisable);
                }
                catch (Exception)
                { }
        }