Adding a .css to <head> tag from codebehind?

G

Guest

I'm inheriting from a custom page class instead of System.Web.UI.Page, and I
want to add a .css or .js link to the page's <head> tag. Can this be done?

I tried this using but it just adds it to the bottom of the page....I need
to somehow reference the <head> server-side?

HtmlGenericControl link = new HtmlGenericControl("LINK");
link.Attributes.Add("rel","stylesheet");
link.Attributes.Add("type","text/css");
link.Attributes.Add("href","/Css/Main.css");
Controls.Add(link);
 
B

Bruce Barker

the supported method is to add a placeholder control in the header section,
that you can update in the code behind. you can also add a runat=server on
the header.

if you want to be tricky, you can walk the page controls collection, peek at
the html in the of generic controls that exist before the form control for
the <header> tag, and update the html.

-- bruce (sqlwork.com)
 
G

Guest

Bruce,

Just curious, what do you mean by supported method? I was trying to find
something on msdn about this. If you have a link, I'd be interested. Thanks,
Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top