Control inside content page to access Master Page Vars
am 18.04.2008 18:45:24 von 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!
Re: Control inside content page to access Master Page Vars
am 18.04.2008 20:32:26 von ge0193387
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.
Re: Control inside content page to access Master Page Vars
am 19.04.2008 08:46:36 von 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
Poofactory wrote:
> 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!