I have a custom control and I want to dynamically insert a link to a stylesheet.
Might not be the best solution of the year but it needs to be done. Any idea how to do it?
Everytime I try, Page.Header is null.
I have a custom control and I want to dynamically insert a link to a stylesheet.
Might not be the best solution of the year but it needs to be done. Any idea how to do it?
Everytime I try, Page.Header is null.
To avoid the problem of multiple stylesheets when adding the control 10 times to the page, change the above code slightly:
By giving the control an ID you can check if it already exists, and so ensure that you only add it the once.
Here's how you would normally add a CSS programatically:
You might need to put a
runat="server"
in thehead
tag: