1

Is there a mechanism to read the value that is SET to the visible property of a control?

ChildControl1.Visible = true;
ChildControl2.Visible = false;

ParentControl.Visible = false;

bool childControl1Visible = ChildControl1.Visible
bool childControl2Visible = ChildControl2.Visible

In the example above, both childControl1Visible and childControl2Visible will return false as neither will be rendered due to the visibility of ParentControl.

I'm looking for a way to determine if a child control has itself been set to visible true/false regardless of the value set on any parent controls.

Robin Day
  • 100,552
  • 23
  • 116
  • 167

1 Answers1

1

There's no way to get the internal value - it's all kept inside an internal bit vector called flags (see source).

You would either have to manually track the visible property elsewhere or wrap the control in your own inherited class where you can override the Visible property and expose the value there. For example:

public class MyTextBox : System.Web.UI.WebControls.TextBox
{
    public bool Visible
    {
        get
        {
            return base.Visible;
        }   
        set
        {
            ReallyVisible = value;
            vase.Visible = value;
        }
    }

    public bool ReallyVisible { get; private set; }
}

You may want to choose a better property name!

Another hacky way would be to use reflection to get access to the internal value. See here for a method of doing that.

DavidG
  • 113,891
  • 12
  • 217
  • 223