Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Disable Child Controls Recursively

, 13 Nov 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
public void ControlStatus(Control control, bool isDisable){ foreach (Control c in control.Controls) if (c.HasControls()) ControlStatus(c, isDisable); else { WebControl wc = c as WebControl; if (wc != null) ...
public void ControlStatus(Control control, bool isDisable)
{
    foreach (Control c in control.Controls)
        if (c.HasControls())
            ControlStatus(c, isDisable);
        else
        {
            WebControl wc = c as WebControl;
 
            if (wc != null)
                wc.Enabled = !isDisable;
        }
}
 
Ignoring exceptions is bad programming practice.
Use 'as' to avoid casting c twice.

License

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

Share

About the Author

jarvisa
Software Developer (Senior) Shaw Inspection Systems Ltd
United Kingdom United Kingdom
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 13 Nov 2010
Article Copyright 2010 by jarvisa
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid