reference master page class from content page base class?

M

Managed Code

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
 
N

Nicole Calinoiu

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

MyMasterPage masterPage = (MyMasterPage)this.Master;
 
M

Managed Code

Eliyahu said:
<%@ 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 said:
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
 
E

Eliyahu Goldin

<%@ MasterType virtualpath="~/myMasterPage.master" %>
will let you access all public members of the master as
this.Master.myMember
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top