Chao
Chao

Reputation: 3043

Conditional ContentPlaceHolder in Master Page

I have two master pages in my project, one for web views and another for emails. In the web master page is a placeholder to put page specific JavaScript, if a page is using this and I try to programmatically change the masterpage to send as an email the server falls over as it can't find the placeholder.

Is there a way to change the behaviour so that if a placeholder can't be found it just doesn't include that bit? I'm thinking maybe on my page base class looping over a collection of placeholders and content tags and removing the ones that don't match up, but I'm not sure if there's a good point in the page lifecycle to do this.

I'm using MVC not WebForms if this makes a difference.

Upvotes: 2

Views: 3202

Answers (2)

Mike J
Mike J

Reputation: 1154

Add the ContentPlaceHolder into the mail masterpage and set the visible property to false and the content from the page for that placeholder won't render.

<asp:ContentPlaceHolder id="javascriptPlaceHoldereHolder1" runat="server" Visible="false" />

Upvotes: 3

womp
womp

Reputation: 116987

You can't have a Content control with a ContentPlaceHolderID that doesn't exist.

Instead of taking the ContentPlaceHolder out, why don't you just provide an empty Content control? It'll just render nothing.

Upvotes: 0

Related Questions