R – Nested MasterPage in SharePoint not working

asp.netmaster-pagesnetsharepointsharepoint-2007

I have a SharePoint 2007 Server and want to create a site with a nested Master Page.

I created a new Master Page, test.master:

<%@ Master MasterPageFile="~masterurl/default.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    Test123
    <b>
    <asp:ContentPlaceHolder runat="server" ID="TestPH" Visible="true" />
    </b>
</asp:Content>

I then created a new Page, Test.aspx

<%@ Page MasterPageFile="test.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TestPH" runat="server">
    TestChild
    <asp:Label Text="Test" runat="server" />
</asp:Content>

I uploaded both test.master and test.aspx to a newly created blank site using SharePoint Designer.

When I call Test.aspx, I only see Test123 from the test.master – it seems to ignore the placeholder. The HTML Output (including an excerpt from the Sharepoint default.master):

<td class='ms-bodyareaframe' valign="top" height="100%">
    <A name="mainContent"></A>
    Test123
    <b>

    </b>
</td>

Now, when I go into Test.aspx and change it's masterpage to default.master and TestPH to PlaceHolderMain, I correctly see TestChild Test, so the page itself works.

Neither the Master nor the ASPX page contain CodeBehind yet, and thus no change to web.config was made (SafeControls…)

I wonder if I need to enable something to allow nested master pages, or if SharePoint 2007 as usual demands the sacrifice of a goat on it's altar…

Best Answer

There is something about the way SharePoint treats the master-page token. This is because they allow you to load master page from the database, it does not have to be in the file system. You can read more about it here: http://msdn.microsoft.com/en-us/library/ms476046.aspx

Since I've never worked with "regular ASP.net" after version 1.1, I have no idea, how master pages SHOULD work.
But, what I've been doing once, is copying the contents of default.master (lives in /12/template/global) to a new file which does not inherit from anything, then I included it in site definition feature and referenced to it in onet.xml file. The technique is described here: http://statto1974.wordpress.com/2007/04/30/using-a-custom-master-page-in-a-site-definition/

EDIT: However, there are several references to this being possible, for instance, this one.

Related Topic