Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Control inside content page to access Master Page Vars

0 views
Skip to first unread message

Poofactory

unread,
Apr 18, 2008, 12:45:24 PM4/18/08
to
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!

cfps.Christian

unread,
Apr 18, 2008, 2:32:26 PM4/18/08
to
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.

wis...@googlemail.com

unread,
Apr 19, 2008, 2:46:36 AM4/19/08
to
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

0 new messages