Dynamically add link to css stylesheet?

G

Guest

Is there a way to dynamically add a reference to the css stylesheet from the
codebehind similarly to the script registration features?

I was thinking of adding this code to a base class and inherit all my pages
from it so the css link below is added to each page automatically in the
<head> section....

<LINK href="/MyApp/Css/MyApp.css" type="text/css" rel="stylesheet">

Thanks, Dave.
 
C

Chris Austin

Hi Dave,

Putting something like the following in your page load event should do the
trick.

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

HTH

-Chris
~
http://weblogs.austinspad.com/caustin
 
G

Guest

Thanks!!!!

Chris Austin said:
Hi Dave,

Putting something like the following in your page load event should do the
trick.

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

HTH

-Chris
~
http://weblogs.austinspad.com/caustin
 
J

Justin Beckwith

There are a few ways to go about this, but the easiest is to make your
head tag runat server, and add a literal control with your HTML.


in your HTML, make the head tag a server side object:

<html>
<head runat="server" id="head">
</head>
<body>
</body>
</html>

then in Page_Load:

Dim l As New Literal
l.Text = "<link rel=""Stylesheet"" type=""text/css""
href=""styles.css"">"
Me.FindControl("head").Controls.Add(l)

hope this works for you!
 

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,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top