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

Disable Child Controls Recursively

, 13 Nov 2010
Rate this:
Please Sign up or sign in to vote.
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)
                { }
        }

License

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

Share

About the Author

PSU Steve
Software Developer (Senior) Self-employed, consultant to US Air Force
United States United States
No Biography provided

Comments and Discussions

 
GeneralI like the "not IsDisable" part :), but why do we need the p... PinmemberAntoun Gorgy8-Nov-10 0:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 13 Nov 2010
Article Copyright 2010 by PSU Steve
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid