Wednesday, 28 October 2009

Adding javascript or style sheet links to page head

You can do this dynamically for any page, even if it's header is provided by a master page elsewhere. Simply use the following code in your Page_Load event:

A link to a JS file. In this case it's Scriptaculous:
Dim jslink As HtmlGenericControl = New HtmlGenericControl("Script")
jslink.Attributes.Add("type", "text/javascript")
jslink.Attributes.Add("src", "/Scripts/scriptaculous.js")

A link to a CSS:
Dim link As HtmlLink = New HtmlLink()
link.Attributes.Add("type", "text/css")
link.Attributes.Add("rel", "stylesheet")
link.Attributes.Add("href", "../css/sortableLists.css")

No comments:

Post a Comment

Comments are moderated, so you'll have to wait a little bit before they appear!