![]() |
|
|
|||||||
![]() |
ASP Net - Dynamically add link to css stylesheet? |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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==?= |
|
|
|
|
#2 |
|
Posts: n/a
|
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 |
|
|
|
#3 |
|
Posts: n/a
|
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==?= |
|
|
|
#4 |
|
Posts: n/a
|
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 |
|
![]() |
| Thread Tools | Search this Thread |
|
|
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 |