473,402 Members | 2,072 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,402 software developers and data experts.

Multiple Master Pages - Inheritance?

Hi,

I want to use 2 master pages, one for the main part of the site, the other
for the admin pages.

They are quite similar, with many shared elements.

Ideally I would like to have a parent master page, which both of these child
master pages are based on, and in turn the final pages are based on one of
these child master pages.

This would form an inheritance hierarchy, so any change could be made to the
parent master page, which would affect both children, or to each child
individually.

Is this possible?

Cheers
Rich.
Feb 18 '07 #1
3 5952
Joe
Hi Rich,

You can do what you want in ASP.NET 2.0.
Create a master page say Site1.master
Now create another master page say Child.master and set it's master to
Site1.master.

Now the problem you're going to get is that VS doesn't support design dev
with embedded master pages. To work around this you'll need to do the
following:

Create a new class like this:
public class BasePage : System.Web.UI.Page
{
private string runtimeMasterPageFile;

public string RuntimeMasterPageFile
{
get
{
return runtimeMasterPageFile;
}
set
{
runtimeMasterPageFile = value;
}
}

protected override void OnPreInit(EventArgs e)
{
if (runtimeMasterPageFile != null)
{
this.MasterPageFile = runtimeMasterPageFile;
}

base.OnPreInit(e);
}
}

Make each of your child pages (content pages) inherit from this base class.
In the aspx page of each child page add the following attrbiute to the top:
RuntimeMasterPageFile="~/Child.master" and make sure that
MasterPageFile="~/Site1.master".

What this does is use the Site1.master at design time but changes it to use
Child.master at runtime.

You still will not be able to use the design tools to create your
Child.master but will be able to use the designer for all content pages.

Note: I found this code on the web but cannot remember where. I would like
to give credit to the person who wrote (if I knew who it was).

Hope this helps.
-Joe
"Rich" <r@r.rwrote in message
news:45**********************@un-2park-reader-01.sydney.pipenetworks.com.au...
Hi,

I want to use 2 master pages, one for the main part of the site, the other
for the admin pages.

They are quite similar, with many shared elements.

Ideally I would like to have a parent master page, which both of these
child master pages are based on, and in turn the final pages are based on
one of these child master pages.

This would form an inheritance hierarchy, so any change could be made to
the parent master page, which would affect both children, or to each child
individually.

Is this possible?

Cheers
Rich.

Feb 18 '07 #2
You can do this, but you lose the IDE support for the pages, so you have to
code blind. Best bet is to complete the pages, as you wish, and refactor the
common bits and then test.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

********************************************
Think outside the box!
********************************************
"Rich" <r@r.rwrote in message
news:45**********************@un-2park-reader-01.sydney.pipenetworks.com.au...
Hi,

I want to use 2 master pages, one for the main part of the site, the other
for the admin pages.

They are quite similar, with many shared elements.

Ideally I would like to have a parent master page, which both of these
child master pages are based on, and in turn the final pages are based on
one of these child master pages.

This would form an inheritance hierarchy, so any change could be made to
the parent master page, which would affect both children, or to each child
individually.

Is this possible?

Cheers
Rich.
Feb 18 '07 #3
Thanks for that, it's a nice solution.

Still wish it wasn't necessary...

At the moment I am just using some conditionals in the template. If that
gets too ugly, I will implement this.

"Joe" <jb*******@noemail.noemailwrote in message
news:Op**************@TK2MSFTNGP05.phx.gbl...
Hi Rich,

You can do what you want in ASP.NET 2.0.
Create a master page say Site1.master
Now create another master page say Child.master and set it's master to
Site1.master.

Now the problem you're going to get is that VS doesn't support design dev
with embedded master pages. To work around this you'll need to do the
following:

Create a new class like this:
public class BasePage : System.Web.UI.Page
{
private string runtimeMasterPageFile;

public string RuntimeMasterPageFile
{
get
{
return runtimeMasterPageFile;
}
set
{
runtimeMasterPageFile = value;
}
}

protected override void OnPreInit(EventArgs e)
{
if (runtimeMasterPageFile != null)
{
this.MasterPageFile = runtimeMasterPageFile;
}

base.OnPreInit(e);
}
}

Make each of your child pages (content pages) inherit from this base
class.
In the aspx page of each child page add the following attrbiute to the
top:
RuntimeMasterPageFile="~/Child.master" and make sure that
MasterPageFile="~/Site1.master".

What this does is use the Site1.master at design time but changes it to
use Child.master at runtime.

You still will not be able to use the design tools to create your
Child.master but will be able to use the designer for all content pages.

Note: I found this code on the web but cannot remember where. I would like
to give credit to the person who wrote (if I knew who it was).

Hope this helps.
-Joe
"Rich" <r@r.rwrote in message
news:45**********************@un-2park-reader-01.sydney.pipenetworks.com.au...
>Hi,

I want to use 2 master pages, one for the main part of the site, the
other for the admin pages.

They are quite similar, with many shared elements.

Ideally I would like to have a parent master page, which both of these
child master pages are based on, and in turn the final pages are based on
one of these child master pages.

This would form an inheritance hierarchy, so any change could be made to
the parent master page, which would affect both children, or to each
child individually.

Is this possible?

Cheers
Rich.


Feb 19 '07 #4

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

Similar topics

20
by: km | last post by:
Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ? thanks in...
1
by: nLella | last post by:
Hello, I am trying to implement page templates in my web application. I am using frame work 1.1. Can you suggest me, if I have to go with Master pages(dll developed by asp.net team) or use...
4
by: John Holmes | last post by:
With ASP we have setup a pretty good method for maintaining a consistent look and feel with minimal effort. The method has it's pros and cons, but the maintenance is minimal. The method consists of...
1
by: Diego | last post by:
Hi all I'd like to understand something about master pages: 1)Why if if try to typecast a masterpage inside a "child page" the compiler tells it dont find the class? I was trying to declare a...
4
by: EagleRed | last post by:
I am writing an ASP.NET 2.0 application that uses more than one master page. Currently, there are two pages, Freedom1.master and Freedom2.master. I have no problems with Freedom1.master. However,...
7
by: xkeops | last post by:
Thinking of creating a website, most of the pages will have a general toolbar menu, a content and a footer. The content will be the only one who's gonna change but the rest (header,footer) will...
4
by: Greg | last post by:
I have a complex page (with 8 complex user controls, and many other asp.net controls.) I have 2 very similiar pages to create, each page differing only from the others in one control. What is...
21
by: raylopez99 | last post by:
Well, contrary to the implication in my 2000 textbook on C# (public beta version), C# does allow multiple inheritance, so long as it's serially chained as follows: class derived02 : derived01 {...
10
by: Cirene | last post by:
I know that sometimes referring to controls deep in a page using a Master Page can be funky. For a website using a standard header/footer/nav, do you prefer using User Controls for the common...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.