母版页中的条件内容占位符

发布于 2024-09-06 14:13:07 字数 273 浏览 3 评论 0原文

我的项目中有两个母版页,一个用于 Web 视图,另一个用于电子邮件。在 Web 母版页中,有一个占位符用于放置页面特定的 JavaScript,如果页面正在使用此占位符,并且我尝试以编程方式更改母版页以作为电子邮件发送,则服务器会因为找不到占位符而崩溃。

有没有办法改变行为,以便如果找不到占位符,它就不会包含该位?我想也许在我的页面基类上循环占位符和内容标记的集合并删除不匹配的标记,但我不确定页面生命周期中是否有这样做的好点。

如果这有什么区别的话,我正在使用 MVC 而不是 WebForms。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

美男兮 2024-09-13 14:13:07

将 ContentPlaceHolder 添加到邮件母版页中并将visible 属性设置为 false,并且该占位符页面中的内容将不会呈现。

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

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" />
惟欲睡 2024-09-13 14:13:07

您不能拥有具有不存在的 ContentPlaceHolderID 的内容控件。

为什么不直接提供一个空的内容控件,而不是取出 ContentPlaceHolder?它不会渲染任何东西。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文