Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best method to make all panels not visible 1

Status
Not open for further replies.

James1981

Programmer
Nov 2, 2002
76
0
0
US
Hi I'm trying to set the visible property on all panels on my page.

Is this possible using a foreach loop?

I have tried using the following but it doesn't work:

Code:
foreach (Panel p in Page.Controls)
{
  do something
}

Does anyone know where I am going wrong?

Cheers, JAmes
 
What happens when you loop through each control on the page, and check for the Panel type?

Your function may have to be recursive to access child controls.
 
foreach (Control c in parent.Controls)
{
if (c.GetType().ToString().Equals("System.Web.UI.WebControls.Panel"))
{
// set to invisible }

if (c.Controls.Count > 0)
{
IterateThroughChildren(c);
}
}
hope this helps
 
thankyou very much mit99mh.

This was just what i needed!!!!

James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top