Accessing properties from nested master pages

Discussion in 'ASP .Net' started by Steve Franks, Sep 19, 2005.

  1. Steve Franks

    Steve Franks Guest

    I have this cool nested master page scenario working great. However what is
    the correct way to be able to access a strongly typed property at the top
    level master from a content page that has a nested master page between the
    content page and the top level master?

    For example, assume the very top level master is called CompanyWide.master.
    And the nested master page is called DepartmentA.master, which inherits from
    CompanyWide master. Last I have a content page test.aspx that is created
    with DepartmentA as its master page.

    OK so now from the test.aspx page's code behind I want to set a public
    property defined in CompanyWide master. However even though the property is
    Public in CompanyWide master, I am not sure how to access it since there is
    another master page in between it (DepartmentA.master).

    What is the right way to do this?

    Do I have to recreate these public properties in DepartmentA to act as a
    stub, so I then call them from test.aspx and it takes them in the setter and
    then sets them in the master? That seems quite messy - wouldn't think that
    would be the way.

    So I thought that maybe DepartmentA master would inherit CompanyWide
    master's public properties since DepartmentA is a nested master of it. But
    when I try:
    (DepartmentA).this.Master I do not see the properties in CompanyWide's so
    it doesn't look like they were inherited. And I cannot do this:
    (CompanyWide).this.Master because test.aspx does not know what type
    "CompanyWide" is.

    Can someone please point me in the right direction here?

    Thanks,

    Steve
     
    Steve Franks, Sep 19, 2005
    #1
    1. Advertising

  2. Steve Franks

    Graham Guest

    You should be able to use ((DepartmentA)this.Master).Property or
    (this.Master as DepartmentA).Property

    "Steve Franks" <> wrote in message
    news:...
    >I have this cool nested master page scenario working great. However what
    >is the correct way to be able to access a strongly typed property at the
    >top level master from a content page that has a nested master page between
    >the content page and the top level master?
    >
    > For example, assume the very top level master is called
    > CompanyWide.master. And the nested master page is called
    > DepartmentA.master, which inherits from CompanyWide master. Last I have a
    > content page test.aspx that is created with DepartmentA as its master
    > page.
    >
    > OK so now from the test.aspx page's code behind I want to set a public
    > property defined in CompanyWide master. However even though the property
    > is Public in CompanyWide master, I am not sure how to access it since
    > there is another master page in between it (DepartmentA.master).
    >
    > What is the right way to do this?
    >
    > Do I have to recreate these public properties in DepartmentA to act as a
    > stub, so I then call them from test.aspx and it takes them in the setter
    > and then sets them in the master? That seems quite messy - wouldn't think
    > that would be the way.
    >
    > So I thought that maybe DepartmentA master would inherit CompanyWide
    > master's public properties since DepartmentA is a nested master of it.
    > But when I try:
    > (DepartmentA).this.Master I do not see the properties in CompanyWide's so
    > it doesn't look like they were inherited. And I cannot do this:
    > (CompanyWide).this.Master because test.aspx does not know what type
    > "CompanyWide" is.
    >
    > Can someone please point me in the right direction here?
    >
    > Thanks,
    >
    > Steve
    >
     
    Graham, Sep 19, 2005
    #2
    1. Advertising

  3. Steve Franks

    Steve Franks Guest

    I thought so too and had tried that before posting. It does not work
    though.

    Steve

    "Graham" <> wrote in message
    news:uC$IE%...
    > You should be able to use ((DepartmentA)this.Master).Property or
    > (this.Master as DepartmentA).Property
     
    Steve Franks, Sep 19, 2005
    #3
  4. Steve Franks

    Steve Franks Guest

    OK, I figured it out. Here it is:
    ((CompanyWide)this.Master.Page.Master).HtmlTitle = "now it is working";

    Be sure you do NOT have a <%@ MasterType VirtualPath="~/whatever.master" %>
    declared or you will get an InvalidCastException thrown at runtime.

    I hope this helps someone else one day.

    Steve
     
    Steve Franks, Sep 19, 2005
    #4
  5. Steve Franks

    Brock Allen Guest

    You can do Master.Master.PropName as long as everyone in the chain has applied
    a <%@ MasterType %>

    http://beta.asp.net/QUICKSTART/aspnet/doc/masterpages/default.aspx#code

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen

    > I have this cool nested master page scenario working great. However
    > what is the correct way to be able to access a strongly typed property
    > at the top level master from a content page that has a nested master
    > page between the content page and the top level master?
    >
    > For example, assume the very top level master is called
    > CompanyWide.master. And the nested master page is called
    > DepartmentA.master, which inherits from CompanyWide master. Last I
    > have a content page test.aspx that is created with DepartmentA as its
    > master page.
    >
    > OK so now from the test.aspx page's code behind I want to set a public
    > property defined in CompanyWide master. However even though the
    > property is Public in CompanyWide master, I am not sure how to access
    > it since there is another master page in between it
    > (DepartmentA.master).
    >
    > What is the right way to do this?
    >
    > Do I have to recreate these public properties in DepartmentA to act as
    > a stub, so I then call them from test.aspx and it takes them in the
    > setter and then sets them in the master? That seems quite messy -
    > wouldn't think that would be the way.
    >
    > So I thought that maybe DepartmentA master would inherit CompanyWide
    > master's public properties since DepartmentA is a nested master of it.
    > But
    > when I try:
    > (DepartmentA).this.Master I do not see the properties in
    > CompanyWide's so
    > it doesn't look like they were inherited. And I cannot do this:
    > (CompanyWide).this.Master because test.aspx does not know what type
    > "CompanyWide" is.
    > Can someone please point me in the right direction here?
    >
    > Thanks,
    >
    > Steve
    >
     
    Brock Allen, Sep 20, 2005
    #5
    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. Doug McCann
    Replies:
    1
    Views:
    1,079
    William Brogden
    Aug 5, 2004
  2. Replies:
    1
    Views:
    3,250
    PeterKellner
    May 16, 2006
  3. Diane Yocom

    Nested Master Pages: Accessing Properties

    Diane Yocom, May 31, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    416
    Diane Yocom
    May 31, 2006
  4. vespaboy
    Replies:
    3
    Views:
    542
    vespaboy
    May 1, 2007
  5. katmagic
    Replies:
    0
    Views:
    1,276
    katmagic
    Dec 26, 2008
Loading...

Share This Page