PDA

View Full Version : how do you add script src urls in header with C# code behind


hotwheelharry
08-06-2009, 03:17 AM
basically, how do you add to the page header...

<script type="text/javascript" src="js/script.js"></script>

dynamically with the page load event handler.

I know how to add actual script code to the page, with registerClientScriptBlock(), but that is not what i want.

I need to register the script url in the page header, not an actual script block.

Any help appreciated.
Thanks!

HostingASPNet
08-06-2009, 07:40 PM
Hello,

You could use this code:

HtmlGenericControl js = new HtmlGenericControl("script");
js.Attributes["type"] = "text/javascript";
js.Attributes["src"] = "js/script.js";
Page.Header.Controls.Add(js);

Regards

hotwheelharry
08-08-2009, 11:21 AM
cool thanks!