How do I access public property in nested masterpage?

Last post 06-30-2004 3:04 PM by SimonCal. 3 replies.

Sort Posts:

  • How do I access public property in nested masterpage?

    06-18-2004, 9:32 PM
    • Member
      85 point Member
    • gamania
    • Member since 06-18-2004, 12:06 AM
    • Posts 17
    I know how to use MasterType to access master page's public property? However, how do I access master page's master page's public property? I tried with Master.Master.PublicProperty, it tells me the type is defined in an assembly not referenced. Any thoughts?
  • Re: How do I access public property in nested masterpage?

    06-19-2004, 3:23 AM
    Answer
    • All-Star
      29,644 point All-Star
    • Fredrik N
    • Member since 06-22-2002, 5:03 AM
    • Sweden
    • Posts 5,334
    • TrustedFriends-MVPs
    Add the MasterType to the sub master page and point it to the base MasterPage. In your content page you set the MasterType to your sub master page (I suppose you know that).
    You also need to add a reference from the content page to your base master page. You do that with .

    Base Master Page:






    Untitled Page












    Base Maste page code:


    public partial class MasterPage_master
    {
    public string Name
    {
    get { return "The Base Master Page"; }
    }
    }


    Sub Master Page:











    Content page:







    Content page code:


    public partial class Default2_aspx
    {
    void Page_Load()
    {
    Response.Write(Master.Master.Name);
    }
    }
    /Fredrik Normén - fredrikn @ twitter

    ASPInsider

    Microsoft MVP, MCSD, MCAD, MCT

    ASPInsiders
    My Blog
  • Re: How do I access public property in nested masterpage?

    06-19-2004, 1:19 PM
    • Member
      85 point Member
    • gamania
    • Member since 06-18-2004, 12:06 AM
    • Posts 17
    Thanks so much. Reference tag is the key point here.
  • Re: How do I access public property in nested masterpage?

    06-30-2004, 3:04 PM
    • Participant
      1,910 point Participant
    • SimonCal
    • Member since 06-10-2002, 4:43 PM
    • Posts 381
    • AspNetTeam
      Moderator
    The Master property on the Page and MasterPage is typed; to make this strongly-typed we have a new directive called the MasterType:


    <%@ mastertype virtualpath="~/mymaster.master" %.

    you should be able to use this to enable strong-typing to public props exposed on the master

    Hope this helps.
    Simon
    This posting is provided "AS IS" with no warranties, and confers no rights.
Page 1 of 1 (4 items)