Dynamically adding a stylesheet to page

January 23, 2006


Dynamically adding a stylesheet to page

There are many situations when you may want to dynamically add a stylesheet to a page. One use case is when a control is being dynamically loaded and it comes with its own stylesheet. If you don’t know that the style is needed in advance or are dealing with an environment where you have a stylesheet for a control but don’t have control of the page (as it is in DotNetNuke), there are two common methods in use:

1) Add a tag: This works but leaves the parent page non-XHTML compliant since is only valid in the section.

2) Add a