...

View Full Version : Accessing Master Page controls from Content Page user control



lbeckman
06-20-2007, 07:30 PM
So here's the current problem.

I've got a Master Page, HelpSiteMaster.master,
and I've got a Content Page, infoFlowContent.aspx.

HelpSiteMaster.master contains many controls, and for example I'll use
<asp:Literal ID="PopupVis" Text="hidden" runat="server"></asp:Literal>,
which manipulates part of my stylesheet.

Now, to access those controls from the code for infoFlowContent.aspx,
found in infoFlowContent.aspx.cs, in my Master Page code I have:



public string PopupVisText
{
set
{
PopupVis.Text = value;
}
}


which exposes the controls, and in the infoFlowContent code I use something like



Master.PopupVisText = "hidden";


to access them.

Now, that all works nicely, but now I have a user control CacheControl.ascx
used in infoFlowContent.aspx, and I need to access the same Master Page
controls in the code associated with this user control, found in CacheControl.ascx.cs.

I tried



Page.Master.PopupVisText = "hidden";


but this keeps giving me


CS0117: 'System.Web.UI.MasterPage' does not contain a definition for 'PopupVisText'


Looked around online for awhile and couldn't find anything useful, so any help would be much appreciated.

rviana
07-18-2007, 06:17 PM
So here's the current problem.

I've got a Master Page, HelpSiteMaster.master,
and I've got a Content Page, infoFlowContent.aspx.

HelpSiteMaster.master contains many controls, and for example I'll use
<asp:Literal ID="PopupVis" Text="hidden" runat="server"></asp:Literal>,
which manipulates part of my stylesheet.

Now, to access those controls from the code for infoFlowContent.aspx,
found in infoFlowContent.aspx.cs, in my Master Page code I have:



public string PopupVisText
{
set
{
PopupVis.Text = value;
}
}


which exposes the controls, and in the infoFlowContent code I use something like



Master.PopupVisText = "hidden";


to access them.

Now, that all works nicely, but now I have a user control CacheControl.ascx
used in infoFlowContent.aspx, and I need to access the same Master Page
controls in the code associated with this user control, found in CacheControl.ascx.cs.

I tried



Page.Master.PopupVisText = "hidden";


but this keeps giving me


CS0117: 'System.Web.UI.MasterPage' does not contain a definition for 'PopupVisText'


Looked around online for awhile and couldn't find anything useful, so any help would be much appreciated.

You just have to cast your Master Page:

((MasterPage)Master).PopupVisText = "hidden";

If your master page class has other name than MasterPage use it instead. By default this is the class name.

Rodney Viana

darshnik1980
07-23-2007, 01:19 PM
Literal Ltl = (Literal)Page.Master.FindControl("PopupVis");
Ltl.Visible = false;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum