Click here to Skip to main content
13,256,123 members (30,677 online)
Click here to Skip to main content
Add your own
alternative version


7 bookmarked
Posted 28 Oct 2010

Disable Child Controls Recursively

, 31 Oct 2010
Rate this:
Please Sign up or sign in to vote.

Trying to disable a div on a certain event, but for a div there is no such a property named Enabled, and if we use attribute["disabled"] the controls inside are not disabled, just have a gray color.. !! Same when using a UserControl that have child controls

The child controls will not be disabled..

So, I wrote a method that uses recursion to go down deep and disable each child Control in any given parent Control.

The method takes two parameters

  • 1st the main control
  • 2nd status flage

// to enable\disable the control & its child controls
public void ControlStatus(Control control, bool isDisable)
        foreach (Control c in control.Controls)
                if (c.HasControls())
                    ControlStatus(c, isDisable);
                    if (isDisable)
                        if (c is WebControl)
                            ((WebControl)c).Enabled = false;
                        if (c is WebControl)
                            ((WebControl)c).Enabled = true;
            catch (Exception)


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


About the Author

Antoun Gorgy
Software Developer
Egypt Egypt
- BSc Computer Engineering
Ain Shams University - Faculty of Engineering

You may also be interested in...


Comments and Discussions

GeneralReason for my vote of 4 Nice Tip Pin
Eswa29-Oct-10 0:31
memberEswa29-Oct-10 0:31 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171114.1 | Last Updated 31 Oct 2010
Article Copyright 2010 by Antoun Gorgy
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid