Page.Header.Controls.Add(控制)添加控件到&lt;身体GT;不&LT; HEAD&GT; [英] Page.Header.Controls.Add(control) is adding controls to <body> not <head>
本文介绍了Page.Header.Controls.Add(控制)添加控件到&lt;身体GT;不&LT; HEAD&GT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在运行时添加一些code头部元素。当我做这在用户控制在网页页面加载速度:
I'm trying add some code at run time to the head element. When I do this in the page load of a user control in the page:
HtmlGenericControl hc = new HtmlGenericControl();
hc.InnerHtml = GetParameter("HeaderCode");
Page.Header.Controls.Add(hc);
控制身体标记结束,作为第一个子元素。例如:
The control ends up in the body tag, as the first child element. For Example:
...
</head>
<body>
<span><meta>Test</meta></span>
...
从我的理解中,Page.Header应该是head元素。在aspx页面,头部有设置 =服务器
属性。
任何想法,我怎么能在注入一个字符串&LT; HEAD&GT;
元素?
Any idea how I can inject a string in to the <head>
element?
推荐答案
头元素可能对内容的类型限制。当我们的JavaScript注入到页眉,我们使用的是LiteralControl吧。
The head element may have restrictions on the type of content. When we inject javascript into the header, we do it using a LiteralControl.
例如:
Page.Header.Controls.Add(New LiteralControl("<script language='javascript' type='text/javascript'>alert('test');</script>"))
这篇关于Page.Header.Controls.Add(控制)添加控件到&lt;身体GT;不&LT; HEAD&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文