reference master page class from content page base class?

Discussion in 'ASP .Net' started by Managed Code, Jul 31, 2006.

  1. Managed Code

    Managed Code Guest

    I have a BasePage class that derives from System.Web.UI.Page. All of my
    content pages derive from this. The derived page classes use the
    following MasterType declaration that follows to reference the master.

    <%@ MasterType TypeName="MyMasterPage" %>

    How do I reference the master page class from the BasePage?


    Thanks...

    mc
     
    Managed Code, Jul 31, 2006
    #1
    1. Advertising

  2. Cast the page's Master property return value to the type of the master.
    e.g.:

    MyMasterPage masterPage = (MyMasterPage)this.Master;


    "Managed Code" <> wrote in message
    news:...
    >I have a BasePage class that derives from System.Web.UI.Page. All of my
    > content pages derive from this. The derived page classes use the
    > following MasterType declaration that follows to reference the master.
    >
    > <%@ MasterType TypeName="MyMasterPage" %>
    >
    > How do I reference the master page class from the BasePage?
    >
    >
    > Thanks...
    >
    > mc
    >
     
    Nicole Calinoiu, Jul 31, 2006
    #2
    1. Advertising

  3. Managed Code

    Managed Code Guest

    Eliyahu Goldin wrote:
    > <%@ MasterType virtualpath="~/myMasterPage.master" %>
    > will let you access all public members of the master as
    > this.Master.myMember
    > --
    > Eliyahu Goldin,
    > Software Developer & Consultant
    > Microsoft MVP [ASP.NET]
    >
    > "Managed Code" <> wrote in message
    > news:...
    > >I have a BasePage class that derives from System.Web.UI.Page. All of my
    > > content pages derive from this. The derived page classes use the
    > > following MasterType declaration that follows to reference the master.
    > >
    > > <%@ MasterType TypeName="MyMasterPage" %>
    > >
    > > How do I reference the master page class from the BasePage?
    > >
    > >
    > > Thanks...
    > >
    > > mc
    > >


    I tried the first option of

    MyMasterPage masterPage = (MyMasterPage)this.Master;

    which generated the following error

    c:\inetpub\wwwroot\WorkFlow\App_Code\PageBase.cs(22,3): error CS0246:
    The type or namespace name 'MyMasterPage' could not be found (are you
    missing a using directive or an assembly reference?)

    This cast works from a content page that derives directly from
    System.Web.UI.Page and that has a corresponding aspx page, but does not
    seem to work from the parent class that is inserted into the derivation
    chain between the content page and System.Web.UI.Page;

    As for the next option of

    <%@ MasterType virtualpath="~/myMasterPage.master" %>

    There is no corresponding content page for this parent class in which
    to insert this directive.
    Is there a content page derivation mechanism that will allow this?

    Thanks,

    mc
     
    Managed Code, Jul 31, 2006
    #3
  4. <%@ MasterType virtualpath="~/myMasterPage.master" %>
    will let you access all public members of the master as
    this.Master.myMember
    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]

    "Managed Code" <> wrote in message
    news:...
    >I have a BasePage class that derives from System.Web.UI.Page. All of my
    > content pages derive from this. The derived page classes use the
    > following MasterType declaration that follows to reference the master.
    >
    > <%@ MasterType TypeName="MyMasterPage" %>
    >
    > How do I reference the master page class from the BasePage?
    >
    >
    > Thanks...
    >
    > mc
    >
     
    Eliyahu Goldin, Jul 31, 2006
    #4
    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.

Share This Page