Home All Groups Group Topic Archive Search About

Dynamically adding a stylesheet

Author
8 May 2006 10:06 PM
Nathan Sokalski
I want to dynamically add a stylesheet using <style type="text/css"></style>
tags. The code that will use this stylesheet will be shared, so I will not
have control over what the user does as far as stuff like adding
runat="server" and id="someid" attributes to the <head> tag of their .aspx
page. I was wondering if there is a way similar to the
RegisterClientScriptBlock method that can be used. Any ideas or suggestions?
Thanks.
--
Nathan Sokalski
njsokal***@hotmail.com
http://www.nathansokalski.com/

Author
9 May 2006 12:53 AM
Peter Bromberg [C# MVP]
Actually, I believe you can get away with RegisterClientScriptBlock even
though it is not "script". Try it.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Show quoteHide quote
"Nathan Sokalski" wrote:

> I want to dynamically add a stylesheet using <style type="text/css"></style>
> tags. The code that will use this stylesheet will be shared, so I will not
> have control over what the user does as far as stuff like adding
> runat="server" and id="someid" attributes to the <head> tag of their .aspx
> page. I was wondering if there is a way similar to the
> RegisterClientScriptBlock method that can be used. Any ideas or suggestions?
> Thanks.
> --
> Nathan Sokalski
> njsokal***@hotmail.com
> http://www.nathansokalski.com/
>
>
>
Author
9 May 2006 4:06 AM
Nathan Sokalski
Thanks! It may not be the intended purpose, or even inside the <head> tag,
but it's good enough for me, and it works.
--
Nathan Sokalski
njsokal***@hotmail.com
http://www.nathansokalski.com/

Show quoteHide quote
"Peter Bromberg [C# MVP]" <pbromberg@yahoo.nospammin.com> wrote in message
news:05979FBF-CEE3-46B4-9E23-A10A92FFDA94@microsoft.com...
> Actually, I believe you can get away with RegisterClientScriptBlock even
> though it is not "script". Try it.
> Peter
>
> --
> Co-founder, Eggheadcafe.com developer portal:
> http://www.eggheadcafe.com
> UnBlog:
> http://petesbloggerama.blogspot.com
>
>
>
>
> "Nathan Sokalski" wrote:
>
>> I want to dynamically add a stylesheet using <style
>> type="text/css"></style>
>> tags. The code that will use this stylesheet will be shared, so I will
>> not
>> have control over what the user does as far as stuff like adding
>> runat="server" and id="someid" attributes to the <head> tag of their
>> .aspx
>> page. I was wondering if there is a way similar to the
>> RegisterClientScriptBlock method that can be used. Any ideas or
>> suggestions?
>> Thanks.
>> --
>> Nathan Sokalski
>> njsokal***@hotmail.com
>> http://www.nathansokalski.com/
>>
>>
>>
Author
9 May 2006 7:53 AM
Flinky Wisty Pomm
I cheat. I've got two repeaters defined in my masterpages, one for
scripts, one for CSS. My base page class has a couple of List<string>'s
and I just call
AddResource("path/to/file", ResourceType.Css) to add resources to those
Lists

Then I bind the repeaters on PreRender so any page events have an
opportunity to add CSS/Js that'll be needed on the client. It's a hack,
but I like my stylesheets and scripts in external files referenced in
the head where they belong.
Author
10 May 2006 10:33 PM
Martijn Saly
Flinky Wisty Pomm wrote:
> I cheat. I've got two repeaters defined in my masterpages, one for
> scripts, one for CSS. My base page class has a couple of List<string>'s
> and I just call
> AddResource("path/to/file", ResourceType.Css) to add resources to those
> Lists
>
> Then I bind the repeaters on PreRender so any page events have an
> opportunity to add CSS/Js that'll be needed on the client. It's a hack,
> but I like my stylesheets and scripts in external files referenced in
> the head where they belong.
>

That sounds like a much better solution. A <script> tag inside the body is
ugly (and invalid XHTML, I believe). And a <style> tag in the body is just
invalid in both HTML and XHTML.

And we all know that production-quality controls generate valid XHTML at
least, right? ;)

--
Thanks,

Martijn Saly
Author
11 May 2006 11:40 PM
MSDN
Flinky Wisty Pomm,

Can you please show an example.
why repeaters...>???

Thank you,

Sa


Show quoteHide quote
"Flinky Wisty Pomm" <Pathoge***@gmail.com> wrote in message
news:1147161222.017984.44680@e56g2000cwe.googlegroups.com...
>I cheat. I've got two repeaters defined in my masterpages, one for
> scripts, one for CSS. My base page class has a couple of List<string>'s
> and I just call
> AddResource("path/to/file", ResourceType.Css) to add resources to those
> Lists
>
> Then I bind the repeaters on PreRender so any page events have an
> opportunity to add CSS/Js that'll be needed on the client. It's a hack,
> but I like my stylesheets and scripts in external files referenced in
> the head where they belong.
>
Author
9 May 2006 3:23 PM
Edwin Knoppert
I don't get it but <%= ... > should do??
I'm using it for resolving the script url.


Show quoteHide quote
"Nathan Sokalski" <njsokal***@hotmail.com> schreef in bericht
news:OBpEhuucGHA.5048@TK2MSFTNGP03.phx.gbl...
>I want to dynamically add a stylesheet using <style
>type="text/css"></style> tags. The code that will use this stylesheet will
>be shared, so I will not have control over what the user does as far as
>stuff like adding runat="server" and id="someid" attributes to the <head>
>tag of their .aspx page. I was wondering if there is a way similar to the
>RegisterClientScriptBlock method that can be used. Any ideas or
>suggestions? Thanks.
> --
> Nathan Sokalski
> njsokal***@hotmail.com
> http://www.nathansokalski.com/
>
Author
9 May 2006 6:12 PM
Nathan Sokalski
<%=...%> would be fine if I was writing the webform that used the
stylesheet, but I am not writing the webform, I am writing a couple external
classes that will be used with webforms.
--
Nathan Sokalski
njsokal***@hotmail.com
http://www.nathansokalski.com/

Show quoteHide quote
"Edwin Knoppert" <n***@hellobasic.com> wrote in message
news:4460b513$0$2022$ba620dc5@text.nova.planet.nl...
>I don't get it but <%= ... > should do??
> I'm using it for resolving the script url.
>
>
> "Nathan Sokalski" <njsokal***@hotmail.com> schreef in bericht
> news:OBpEhuucGHA.5048@TK2MSFTNGP03.phx.gbl...
>>I want to dynamically add a stylesheet using <style
>>type="text/css"></style> tags. The code that will use this stylesheet will
>>be shared, so I will not have control over what the user does as far as
>>stuff like adding runat="server" and id="someid" attributes to the <head>
>>tag of their .aspx page. I was wondering if there is a way similar to the
>>RegisterClientScriptBlock method that can be used. Any ideas or
>>suggestions? Thanks.
>> --
>> Nathan Sokalski
>> njsokal***@hotmail.com
>> http://www.nathansokalski.com/
>>
>
>
Author
8 Jul 2006 4:01 AM
Kris
K.Scott Allen provided a useful trick for doing that.

The ContentPlaceHolder ¨C Not Just For Content
http://odetocode.com/Blogs/scott/archive/2006/04/10/3258.aspx