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, 03: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, 05: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.





Chris Austin
  Reply With Quote
Old 11-01-2004, 05: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.

>
>
>



=?Utf-8?B?RGF2ZQ==?=
  Reply With Quote
Old 11-02-2004, 02: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.



Justin Beckwith
  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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to open web link in an email Pravin Chauhan General Help Related Topics 1 09-10-2009 02:52 AM
how to create an new webform with codebehind dynamically using c# in asp.net?. krish200 Software 1 12-18-2007 09:16 PM
Grid view in link using C# yogarajan Software 0 05-05-2007 08:28 AM
How i can populate all fileds dynamically in jsp using javascript? vijendra Software 1 10-06-2006 01:33 PM
Re: Question about MS critical updates John Coode A+ Certification 0 06-30-2004 06:08 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46