5

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?

2
  • i'm struggling to find a solution to this same problem as well. in the year or so since you asked, did you ever find a convenient way to do this? Commented Sep 15, 2011 at 20:22
  • Not really. The nested placeholder solution works well, though it's obviously ugly. I've sinced move to the Razor view engine, which has a much nicer system for optionally rendering page sections, replacing content only when you want, etc. Commented Sep 20, 2011 at 18:26

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

I'd hate to have to duplicate that all over the place. We're talking about quite a few pages.
Quite a few master pages you mean? Because you only have to do it in the (child) master pages.
Two years and a full redisign and migration to Sitefinity later, thus actually makes sense.
1

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

2 Comments

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 - Based on your two comments it sounds like you want your cake and to eat it too.
1

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.

1 Comment

When I add a new "Web Form using Master Page" the designer will override all place holders found in master page. Is there a way to tell not to override one of them?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.