In the code behind, we need to add the lbPanelShow_Click
which will handle the OnClick of all of the "LinkButtons" that we
added, because we told it to earlier.
Listing 5
protected void lbPanelShow_Click(object sender, EventArgs e)
{
// your sender would be the link button that you clicked.
LinkButton oLbl = (LinkButton)sender;
// now get the form
Control oFrm = Page.Form;
//loop through the Forms control collection
foreach (Control oCtl in oFrm.Controls)
{
// you will find the place holder controls here
if (oCtl is ContentPlaceHolder)
{
// loop through the placeholder's control collection
foreach(Control oCtl in ctl.Controls) {
// we only want to access our panel controls
if (ctl1 is Panel)
{
switch (oLbl.Text) {
case "lb1":
if (ctl1.ID == "pnl1")
{
ctl1.Visible = true;
}
else
{
ctl1.Visible = false;
}
break;
case "lb2":
if (ctl1.ID == "pnl2")
{
ctl1.Visible = true;
}
else
{
ctl1.Visible = false;
}
break;
case "lb3":
if (ctl1.ID == "pnl3")
{
ctl1.Visible = true;
}
else
{
ctl1.Visible = false;
}
break;
case "lb4":
if (ctl1.ID == "pnl4")
{
ctl1.Visible = true;
}
else
{
ctl1.Visible = false;
}
break;
default:
break;
}
}
}
}
} //end foreach loop
}// end procedure lbPanelShow_Click
Now that you have done that, try it out. You will see it
performs rather nicely.