Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

Disable Child Controls Recursively

5.00/5 (1 vote)
13 Nov 2010CPOL 10.2K  
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 enabledisable 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)
        { }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)