views:

766

answers:

2

I've got a "Master" Masterpage, and I've got 2 "Sub" Masterpages. Those 2 subs have their masterpage property set to the "Master" Masterpage. All good so far.

Well, I was told today to also make Sub1 and Sub2 actually "inherit" from the Master Masterpage. I thought they were being imprecise with their language, but no, she wanted me to change the Class definition to

public partial class Sub2 : TheMaster

(those aren't the names).

So, now I've got Sub1 and Sub2 that are master pages, and have a master page of TheMaster, and ALSO they are of the class of "TheMaster"

I'm quite confused by this, and not sure what kinds of effects this will have. It seems to compile and run fine right now, but we are just starting this 6 month project today, and I don't want to get to month 5 and find out that we have a major design flaw.

Can anyone tell me that this is totally fine, or that we are completely messed up?

I'm scared...hold me.

EDIT: Clarification -- the reason she wanted me to also inherit from the master master page is that we set some things in that page, and we want them available to the sub master pages. Things like the current node in the sitemap that the rendered page is, some user account stuff, and much more.

+1  A: 

Basically what you have done is setup the page so that the class inherits all of the items from the specified base. The hookup of the "Masterpage" property, creates a weak association, and renders content inside of a specific structure. The class inheriting from the base moves the logic forward, into a manner where rather than just having it execute, you can override it.

Now, after thinking about it, you most likely do not want the MasterPage property set....but just the class inheritance

Mitchel Sellers
Okay, but why? And how would I specify content areas in the master master page, and then use those areas and specify new content areas in the sub master pages if I don't want the master page property set?
Matt Dawdy
Overall, it depends onwhat you are trying to do, if the sub pages need to override method functionality of the parent, then you are in a bit of a trickly situation. If you just need the info, make the items public on the main page, and reference this.parent to get to them.
Mitchel Sellers
+2  A: 

It is indeed possible to have nested master pages - see http://msdn.microsoft.com/en-us/library/x2b3ktt7.aspx for a reference.

EDIT as per comment

I don't believe your sub master page should be inheriting from the main master page in the code behind.

Each master page, including the sub master pages should inherit directly from MasterPage, i.e. public partial class Sub1 : System.Web.UI.MasterPage.

Only the ASP markup of the sub master page should be referencing the main master page, i.e. <%@ Master Language="C#" MasterPageFile="~/TheMaster.master" ... />

If you add your sub master page to the project via the VS UI, selecting TheMaster.master as the master page then you will see that this how things are set up. Master page usage is designed to be only via content (markup), and not via class inheritance.

AdamRalph
I know it is possible. I stated that in my post. I told you how I have it setup and said how it was working. My questions was more toward SHOULD I be both specifying a master page and inheriting from the same master page?
Matt Dawdy