litterbugkid
litterbugkid

Reputation: 3666

Is there a way to get a list of all the visible properties on a page?

I want to get a list of all the visible properties on a page within the OnClick() method of a particular button. Is there a way to do this programmatically in c# within asp.net?

Upvotes: 0

Views: 137

Answers (1)

Blachshma
Blachshma

Reputation: 17405

You'll need to recursivly itterate all the controls in the page and find the visible ones :

List<Control> visibleList = null;
protected void FindVisibleControls(Control parent) 
{
    foreach(Control c in parent.Controls) 
    {
       if (c.Visible)
       {
          visibleList.Add(c);
       }

       if (c.HasControls())
          FindVisibleControls(c);
    }
}

Usage - In your button click call it like this:

protected Button1_Click(object sender, EventArgs e)
{
   visibleList = new List<Control>();
   FindVisibleControls(this);
}

Upvotes: 2

Related Questions