Include javascript programmatically using ASP.NET 2.0

The thing is I want to include javascript into the page programmatically mainly because I want to use the full url for the source of the javascript.

So I put these on the code behind during the OnLoad event.

int i = 1;
HtmlGenericControl script = new HtmlGenericControl("script");
script.Attributes.Add("type","text/javascript");
script.Attributes.Add("src",Page.ResolveUrl("~/your url"));
//add after the title tag
Page.Header.AddAt(i++,script);

Tags:

Thursday, September 27th, 2007 code snippet, programming

No comments yet.

Leave a comment

Search

 

My Flickr

DSC_3950P4054890P4054887