Control inside content page to access Master Page Vars

Discussion in 'ASP .Net' started by Poofactory, Apr 18, 2008.

  1. Poofactory

    Poofactory Guest

    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!
     
    Poofactory, Apr 18, 2008
    #1
    1. Advertising

  2. 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.
     
    cfps.Christian, Apr 18, 2008
    #2
    1. Advertising

  3. Poofactory

    Guest

    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!
     
    , Apr 19, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon

    app vars and cache vars

    Jon, Dec 14, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    425
  2. Replies:
    2
    Views:
    484
    Siberwulf
    Sep 15, 2006
  3. jobs
    Replies:
    1
    Views:
    486
    clintonG
    Dec 13, 2006
  4. Mufasa
    Replies:
    1
    Views:
    323
    Frederik Van Lierde
    Aug 22, 2008
  5. Linuxguy123
    Replies:
    7
    Views:
    732
    Paddy O'Loughlin
    Feb 20, 2009
Loading...

Share This Page