【发布时间】:2010-02-03 15:40:39
【问题描述】:
我有一个需要以编程方式将 JavaScript 引用注入页面的服务器控件。它是引用 Microsoft 的 Bing 地图控件,该控件需要将 &s=1 附加到脚本 URL 以通过 SSL 使用。问题在于.NET Framework 对属性进行编码并将& 更改为&(使用Reflector 验证)。在此之后的某个时间点,& 将被完全删除。
所需的脚本标签:
<script type="text/javascript"
src="https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&s=1">
</script>
尝试 1:
var clientScriptManager = this.Page.ClientScript;
if (!clientScriptManager.IsClientScriptIncludeRegistered(this.GetType(), "BingMapControl"))
{
clientScriptManager.RegisterClientScriptInclude(
this.GetType(), "BingMapControl",
"https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&s=1");
}
尝试 2:
HtmlGenericControl include = new HtmlGenericControl("script");
include.Attributes.Add("type", "text/javascript");
include.Attributes.Add("src",
"https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&s=1");
this.Page.Header.Controls.Add(include);
有什么想法吗?
【问题讨论】:
标签: asp.net javascript encoding attributes