Friday, May 21, 2004
« The Ultimate Workstation | Main | SQL Reporting Services »

Many developers use Panels to programmatically show and hide different sections of a page, such as for a multi-step wizard interface or different areas of administration. Here is a series of overloaded methods I came up with for making it easier to show and hide Panels on a page.  You'll notice that some of the overloads include a parent control, for cases where you need to show/hide a Panel inside another Panel or PlaceHolder.

1  #region private void ShowPanel(...)   
2
3  private void HideAllPanels(Control parent)
4  {
5   foreach (Control c in parent.Controls)
6   {
7    if (c is Panel)
8    {
9     c.Visible = false;
10    }
11   }
12  }
13
14  private void ShowPanel(Panel showPanel)
15  {
16   ShowPanel(showPanel, this);
17  }
18
19  private void ShowPanel(Panel showPanel, Control parent)
20  {
21   foreach(Control c in parent.Controls)
22   {
23    if (c is Panel)
24    {
25     c.Visible = (c == showPanel);
26    }
27   }
28
29  }
30
31  private void ShowPanel(string panelID)
32  {
33   ShowPanel(panelID, this);
34  }
35
36  private void ShowPanel(string panelID, Control parent)
37  {
38   Panel p = (Panel) parent.FindControl(panelID);
39   ShowPanel(p, parent);
40  }
41  #endregion
Friday, May 21, 2004 2:16:00 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [0]  | 
Comments are closed.