开发者

Conditional ContentPlaceHolder in Master Page

开发者 https://www.devze.com 2023-01-04 11:38 出处:网络
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 programma

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 se开发者_开发百科nd 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.


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" />


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消