Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Masterpages and adding content to the Head

Masterpages and adding content to the Head

Scheduled Pinned Locked Moved ASP.NET
javascriptcsharpcssasp-netperformance
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Skoder
    wrote on last edited by
    #1

    Hello, i just wanted to know which is the best / fastest (performance) way to add either references to either stylesheets or javascript files (js) inside the tag ? As i am using masterpages i am using asp.net 2.0 Right now to add a stylesheet reference i do the following. HtmlLink ss = new HtmlLink(); ss.Href = "/SomeStylesheet.css"; ss.Attributes.Add("rel", "stylesheet"); ss.Attributes.Add("type", "text/css"); Header.AddParsedSubObject(ss); But this leaves me no possibility to add a tag in the head. Also i wonder if it has to be that difficult to add a stylesheet to a specific page ? I hope it was possible to do something like Header.addElement(""); Soo it dont have to parse the element every time the page is called. Please notice i want to add it to the head. Martin :)

    S 1 Reply Last reply
    0
    • S Skoder

      Hello, i just wanted to know which is the best / fastest (performance) way to add either references to either stylesheets or javascript files (js) inside the tag ? As i am using masterpages i am using asp.net 2.0 Right now to add a stylesheet reference i do the following. HtmlLink ss = new HtmlLink(); ss.Href = "/SomeStylesheet.css"; ss.Attributes.Add("rel", "stylesheet"); ss.Attributes.Add("type", "text/css"); Header.AddParsedSubObject(ss); But this leaves me no possibility to add a tag in the head. Also i wonder if it has to be that difficult to add a stylesheet to a specific page ? I hope it was possible to do something like Header.addElement(""); Soo it dont have to parse the element every time the page is called. Please notice i want to add it to the head. Martin :)

      S Offline
      S Offline
      Skoder
      wrote on last edited by
      #2

      It seems that noone knows how to do this... so i thought i would share it now that i have found out... If anyone is interested you can add the tag to the header the following way. HtmlGenericControl js = new HtmlGenericControl("script"); js.Attributes.Add("src", "/whatever.js"); js.Attributes.Add("type", "text/javascript"); Header.AddParsedSubObject(js); When using masterpages you can actually also place a content placeholder in the head and use it though it might not be the right way to do it. Martin </x-turndown>

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups