如何在ASP.NET中以编程方式创建HTML注释

时间:2021-06-15 21:11:42

Consider this snippet:

考虑一下这个代码片段:

<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]—>

I have access to the Page object. So I can do something like this:

我可以访问Page对象。我可以这样做:

Page.Header.Controls.Add(new HtmlGenericControl())

How am I able to insert the above snippet to the ASP.NET Page's Header or Body?

如何将上面的代码段插入到ASP中。网页的标题还是正文?

2 个解决方案

#1


3  

This seems hacky and there's probably a nicer solution, but this seems to work:

这似乎很陈腐,可能还有更好的解决办法,但这似乎行得通:

protected void Page_Load(object sender, EventArgs e)
{
    Literal comment = new Literal();
    comment.Text = @"<!--[if lt IE 9]><script src='//html5shiv.googlecode.com/svn/trunk/html5.js'></script><![endif]-->";
    Page.Header.Controls.Add(comment);
}

#2


-1  

you can use page.clientscript.add("pageload",'')

您可以使用page.clientscript.add(“新”、“)

#1


3  

This seems hacky and there's probably a nicer solution, but this seems to work:

这似乎很陈腐,可能还有更好的解决办法,但这似乎行得通:

protected void Page_Load(object sender, EventArgs e)
{
    Literal comment = new Literal();
    comment.Text = @"<!--[if lt IE 9]><script src='//html5shiv.googlecode.com/svn/trunk/html5.js'></script><![endif]-->";
    Page.Header.Controls.Add(comment);
}

#2


-1  

you can use page.clientscript.add("pageload",'')

您可以使用page.clientscript.add(“新”、“)