![]() |
|
|
|||||||
![]() |
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. |
|
|
|
#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. > > > |
|
|
|
#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. |
|