views:

60

answers:

3

I have a series of nested master pages, like so:

site.master:

<asp:ContentPlaceHolder ID="SearchFormContent" runat="server">
<%Html.RenderPartial("SearchFormControl"); %>
</asp:ContentPlaceHolder>

in the nested (child) master page, area.master

<asp:Content ContentPlaceHolderID="SearchFormContent" ID="SearchFormContentContainer" runat="server">
<asp:ContentPlaceHolderID="SearchFormContent" runat="server"/>
</asp:ContentPlaceHolder>

I have two separate content pages. One wants to add its own content to SearchFormContent, the other would like to keep the content that was defined in the top-level master page. Of course, since the child master page defines content for the SearchFormContent block so that the child pages can potentially access it, the content defined in the top level master page is obliterated.

Any way to do this?

+1  A: 

Remove all your ContentPlaceHolders and leave the SearchFormControl directly on the site.master. If you never want to override the SearchFormControl then you don't need to define the ControlPlaceHolders

BritishDeveloper
The problem is that I DO want to override the SearchFormControl content. It is rendered differently in a few different areas of the site, but some areas need to use the default content from the top level site master page.
David Lively
@David Lively - Based on your two comments it sounds like you want your cake and to eat it too.
jfar
+1  A: 

I can't think of any way other than having the following in your child master page

<asp:Content ContentPlaceHolderID="SearchFormContent" ID="SearchFormContentContainer" runat="server">
    <asp:ContentPlaceHolder ID="SearchFormContent" runat="server">
        <%Html.RenderPartial("SearchFormControl"); %>
    </asp:ContentPlaceHolder>
</asp:ContentPlaceHolder>

Nasty I know, but its the only way I can think of when using master pages.

HTHs,
Charles

Charlino
I'd hate to have to duplicate that all over the place. We're talking about quite a few pages.
David Lively
Quite a few master pages you mean? Because you only have to do it in the (child) master pages.
Charlino
+1  A: 

you can put content in the contentPlaceHolder on the masterpage. that will be rendered by default if you don't override the with a content on a child page.

Stephane