473,385 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

reference master page class from content page base class?

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

Jul 31 '06 #1
3 2317
Cast the page's Master property return value to the type of the master.
e.g.:

MyMasterPage masterPage = (MyMasterPage)this.Master;
"Managed Code" <ma*********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
>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
Jul 31 '06 #2
<%@ 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" <ma*********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
>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

Jul 31 '06 #3
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" <ma*********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
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(2 2,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

Jul 31 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: multiformity | last post by:
So I have been working on an opensource project for a while, and decided to really try to make it look better after focusing on the functionality most of this time. Up to now, I have simply used a...
0
by: Abraham Andres Luna | last post by:
i have a master page: <%@ Master Language="C#" %> <html> <head> <title>CRM - RDK Truck Sales & Service</title> </head> <body> <form runat="server"> <asp:contentplaceholder...
4
by: RedHair | last post by:
I have a base page class A which inherits System.Web.UI.Page class then a aspx page B inherits class A and have a master page C. There is a property D (a string variable) in the master page C. ...
1
by: Joey | last post by:
Hello, I have tried to programmatically set the theme for my master page by putting code in a "Page_PreInit" fuction in the master page's code behind. However, when I set a breakpoint there and...
1
by: LilC | last post by:
I'm creating an application that has a standard layout for all pages. The information that is displayed in the layout will be dynamic based on the user that is logged in. Thus when a page is...
0
by: Managed Code | last post by:
Hello All, Here is my issue and thanks in advance for any assistance. I have a base page with a dropdownlist that fires an event with the selected index. The content page catches the event and...
2
by: shapper | last post by:
Hello, I have 2 pages: Page1.aspx and Page2.aspx. The two pages have common design parts but also not common design parts. Is it possible to create something like this: MasterPageA |
6
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
I am trying to access a Public property on a Master Page from a Base Page. On the content pages I have the MasterType Directive set up as follows: <%@ MasterType virtualpath="~/Master.master" %>...
1
by: Matty J | last post by:
Excellent, thanks Nathan. The problem I'm having is that I want the variable set in the *Master* page base class. Setting the variable in the Master Base Class Page_PreInit event doesn't seem to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.