Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Dynamically add link to css stylesheet?

 
Thread Tools Search this Thread
Old 11-01-2004, 02:00 PM   #1
Default Dynamically add link to css stylesheet?


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.


=?Utf-8?B?RGF2ZQ==?=
  Reply With Quote
Old 11-01-2004, 04:07 PM   #2
Chris Austin
 
Posts: n/a
Default Re: Dynamically add link to css stylesheet?

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

"Dave" <> wrote in message
news:6A8FD46E-5550-4C48-B70E-...
> 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.



  Reply With Quote
Old 11-01-2004, 04:33 PM   #3
=?Utf-8?B?RGF2ZQ==?=
 
Posts: n/a
Default Re: Dynamically add link to css stylesheet?

Thanks!!!!

"Chris Austin" wrote:

> 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
>
> "Dave" <> wrote in message
> news:6A8FD46E-5550-4C48-B70E-...
> > 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.

>
>
>

  Reply With Quote
Old 11-02-2004, 01:14 AM   #4
Justin Beckwith
 
Posts: n/a
Default Re: Dynamically add link to css stylesheet?

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!





"Dave" <> wrote in message news:<6A8FD46E-5550-4C48-B70E->...
> 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.

  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump