Control inside content page to access Master Page Vars

  • Thread starter Thread starter Poofactory
  • Start date Start date
P

Poofactory

HI,

I have a control on a content page that I need to access and modify a
MasterPage variable.

I can find the control alright:

if (Parent.Page.Master.FindControl("Adserver_TopBanner1") !=
null)
{

}

But I cannot figure out how to cast it so I can change the MasterPage
vars.

Any help would be greatly appreciated.

Thanks!
 
When I had to manipulate variables on the master page I simply created
properties to do it. Every once in a while did the master page load
correctly that I could just use the straight intellisense, but most of
the time I had to do it like this which does make it more
understandable.

MyMasterPage mmp = (MyMasterPage)this.Master;
mmp.MyProperty = "value";

Within the property code you could have it set the control's data to
what you want, or even make the property a method instead.
 
Hi,

What type of control is it? Suppose it's a Label:

Label banner = (Label)
Parent.Page.Master.FindControl("Adserver_TopBanner1");

If you don't know the type, there is no need for a cast, but you will
only be able to access the properties and methods that the Control
class defines.

On the other hand, what Christian suggested is also a good option. In
your master page, you could define a property as:

public string MyProperty {
get {
return Adserver_TopBanner1.Text;
}
set {
this.Adserver_TopBanner1.Text = value;
}
}

And then, you can access it as suggested in the above post.

============
Regards,
Steve
www.stkomp.com
 
Back
Top