V
vcuankitdotnet
I have one .aspx page that contains multiple user controls. Based on
the form requested, I would like to loop through all of the user
controls on the page and display the one requested by using the ID of
the user control.
The following code is used in my .aspx page containing all the user
controls.
Is there an easier way to accomplish this other than the way I am
currently doing it:
foreach(Control __cntrl in this.Controls)
{
if (__cntrl is MasterPage)
{
foreach (Control cntrl in __cntrl.Controls)
{
if (cntrl is HtmlForm)
{
foreach (Control cnt in cntrl.Controls)
{
if (cnt is ContentPlaceHolder &&
cnt.ID == "MyContentArea")
{
foreach (Control cn in
cnt.Controls)
{
if (cn is UserControl)
{
if (cn.ID == formID)
{
cn.Visible = true;
}
else
{
cn.Visible = false;
}
}
}
}
}
}
}
}
}
the form requested, I would like to loop through all of the user
controls on the page and display the one requested by using the ID of
the user control.
The following code is used in my .aspx page containing all the user
controls.
Is there an easier way to accomplish this other than the way I am
currently doing it:
foreach(Control __cntrl in this.Controls)
{
if (__cntrl is MasterPage)
{
foreach (Control cntrl in __cntrl.Controls)
{
if (cntrl is HtmlForm)
{
foreach (Control cnt in cntrl.Controls)
{
if (cnt is ContentPlaceHolder &&
cnt.ID == "MyContentArea")
{
foreach (Control cn in
cnt.Controls)
{
if (cn is UserControl)
{
if (cn.ID == formID)
{
cn.Visible = true;
}
else
{
cn.Visible = false;
}
}
}
}
}
}
}
}
}