将元素从 .NET 中的 contentplaceholder 添加到母版页的标头
我遇到了问题
场景如下:
提交表单后,用户收到一条消息,表示“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想到了两件事。第一个可能有点矫枉过正,但也可能对其他事情有用:在标头的母版页中添加一个新的内容区域,然后您可以使用它来添加所需的任何标头元素。或者,您可能只需在标题中添加一个占位符即可达到相同的效果。
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.