Sandro
Sandro

Reputation: 3160

How can I programmatically create a HTML comment in ASP.NET

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.Header.Controls.Add(new HtmlGenericControl())

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

Upvotes: 3

Views: 373

Answers (2)

Alistair Findlay
Alistair Findlay

Reputation: 1154

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);
}

Upvotes: 3

MahendraPrabu
MahendraPrabu

Reputation: 1

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

Upvotes: -1

Related Questions