S
sck10
Hello,
I am trying to add the following to a App_Code class. The error I am
getting references "Page.Controls". I would like to call this from my
content page which uses MasterPages
I read the following from Steven Cheng, but am having a hard time following:
In ASP.NET 2.0, the pages and usercontrols and their codebehind classes are
dynamically compiled at runtime. However, the dynamic compilation is
possible to compile the page or usercontrols's class into separate
assemblies(due to the folder structure and location of the page and
usercontrols). Thus, in your utility class (you put in App_Code or an
external assembly), it will not see those page/usercontrol classes(compiled
in a different dynamic compiled assembly). For your scenario, you want to
reference some certain usercontrol through their concrete type, I think you
may consider defining some base usercontrol class for your usercontrols,
these base classes can be put in App_Code source files or in an external
assembly(class library project), then you can make the usercontrols(in your
web application) derive from those base classes, e.g.
=============
public partial class usercontrols_HelloUC : MyBaseUserControlClass
{
........................
}
=============
Thus, you can reference the usercontrol instance type the base class type in
your utility class.
.. Any help with this would be appreciated...
sck10
public void SecurityHidePanels()
{
foreach (Control ctlMaster in Page.Controls)
{ // Page
if (ctlMaster is MasterPage)
{ // MasterPage
foreach (Control ctlForm in ctlMaster.Controls)
{
if (ctlForm is HtmlForm)
{ // HtmlForm
foreach (Control ctlContent in ctlForm.Controls)
{
if (ctlContent is ContentPlaceHolder)
{ // ContentPlaceHolder
foreach (Control ctlChild in ctlContent.Controls)
{ //Hide All Panel
if (ctlChild is Panel)
{
ctlChild.Visible = false;
}
}
}
}
}
}
}
}
}
I am trying to add the following to a App_Code class. The error I am
getting references "Page.Controls". I would like to call this from my
content page which uses MasterPages
I read the following from Steven Cheng, but am having a hard time following:
In ASP.NET 2.0, the pages and usercontrols and their codebehind classes are
dynamically compiled at runtime. However, the dynamic compilation is
possible to compile the page or usercontrols's class into separate
assemblies(due to the folder structure and location of the page and
usercontrols). Thus, in your utility class (you put in App_Code or an
external assembly), it will not see those page/usercontrol classes(compiled
in a different dynamic compiled assembly). For your scenario, you want to
reference some certain usercontrol through their concrete type, I think you
may consider defining some base usercontrol class for your usercontrols,
these base classes can be put in App_Code source files or in an external
assembly(class library project), then you can make the usercontrols(in your
web application) derive from those base classes, e.g.
=============
public partial class usercontrols_HelloUC : MyBaseUserControlClass
{
........................
}
=============
Thus, you can reference the usercontrol instance type the base class type in
your utility class.
.. Any help with this would be appreciated...
sck10
public void SecurityHidePanels()
{
foreach (Control ctlMaster in Page.Controls)
{ // Page
if (ctlMaster is MasterPage)
{ // MasterPage
foreach (Control ctlForm in ctlMaster.Controls)
{
if (ctlForm is HtmlForm)
{ // HtmlForm
foreach (Control ctlContent in ctlForm.Controls)
{
if (ctlContent is ContentPlaceHolder)
{ // ContentPlaceHolder
foreach (Control ctlChild in ctlContent.Controls)
{ //Hide All Panel
if (ctlChild is Panel)
{
ctlChild.Visible = false;
}
}
}
}
}
}
}
}
}