将元素从 .NET 中的 contentplaceholder 添加到母版页的标头

发布于 2024-09-08 01:00:02 字数 493 浏览 0 评论 0原文

我遇到了问题

场景如下:

提交表单后,用户收到一条消息,表示“OK”,并在 2 秒后重定向到另一个页面。

问题是,当插入成功时,我向母版页的标题添加了一个 HtmlMeta 元素,但是当我从 contentplaceholder 插入时,我收到了以下错误:

“ 无法修改 Controls 集合,因为该控件包含代码块(即 <% ... %>)。 “

有什么解决方案吗?

感谢

编辑:

public static void MetaRedirect(Page p, string url) { HtmlMeta meta = new HtmlMeta();

        meta.Content = "2;url=" + url;
        meta.HttpEquiv = "refresh";

        p.Header.Controls.Add(meta);
    }

I'm with a problem

The scenario is the follow:

After submitting a form the user recieves one message says OK, and is redirected to another page after 2seconds.

The problem is, when insert is sucefully, i add to the header of the masterpage a HtmlMeta element, but when i'm inserting from the contentplaceholder, i recieved a followed error:

"
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). "

any solution guys?

apreciated

Edit:

public static void MetaRedirect(Page p, string url) { HtmlMeta meta = new HtmlMeta();

        meta.Content = "2;url=" + url;
        meta.HttpEquiv = "refresh";

        p.Header.Controls.Add(meta);
    }

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

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

发布评论

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

评论(1

愛放△進行李 2024-09-15 01:00:02

我想到了两件事。第一个可能有点矫枉过正,但也可能对其他事情有用:在标头的母版页中添加一个新的内容区域,然后您可以使用它来添加所需的任何标头元素。或者,您可能只需在标题中添加一个占位符即可达到相同的效果。

Two things spring to mind. The first is potentially overkill but could be useful for other things as well: add a new content area in the master page in the header that you can then use to add any header elements you want. Alternatively you can probably just add a placeholder into your header for much the same effect.

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