Control inside content page to access Master Page Vars

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!
 
C

cfps.Christian

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.
 
W

wisccal

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top