473,327 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Dynamically adding a stylesheet

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
nj********@hotmail.com
http://www.nathansokalski.com/
May 8 '06 #1
8 1269
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
nj********@hotmail.com
http://www.nathansokalski.com/

May 9 '06 #2
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
nj********@hotmail.com
http://www.nathansokalski.com/

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:05**********************************@microsof t.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
nj********@hotmail.com
http://www.nathansokalski.com/

May 10 '06 #3
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.

May 10 '06 #4
I don't get it but <%= ... > should do??
I'm using it for resolving the script url.
"Nathan Sokalski" <nj********@hotmail.com> schreef in bericht
news:OB**************@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
nj********@hotmail.com
http://www.nathansokalski.com/

May 10 '06 #5
<%=...%> 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
nj********@hotmail.com
http://www.nathansokalski.com/

"Edwin Knoppert" <ne**@hellobasic.com> wrote in message
news:44**********************@text.nova.planet.nl. ..
I don't get it but <%= ... > should do??
I'm using it for resolving the script url.
"Nathan Sokalski" <nj********@hotmail.com> schreef in bericht
news:OB**************@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
nj********@hotmail.com
http://www.nathansokalski.com/


May 10 '06 #6
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
May 10 '06 #7
Flinky Wisty Pomm,

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

Thank you,

Sa
"Flinky Wisty Pomm" <Pa********@gmail.com> wrote in message
news:11*********************@e56g2000cwe.googlegro ups.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.

May 11 '06 #8
K.Scott Allen provided a useful trick for doing that.

The ContentPlaceHolder ¨C Not Just For Content
http://odetocode.com/Blogs/scott/arc...4/10/3258.aspx
Jul 8 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: wjbell | last post by:
I have a piece of javascript I need to modify. Right now it changes a stylesheet in the document between style.css and no_indent.css. These are in the head of my document: <link rel=stylesheet...
20
by: David | last post by:
I have a one-line script to add an onunload event handler to the body of the document. The script is as follows: document.getElementsByTagName("BODY").onunload=function s() {alert("s")} Now...
3
by: Dave | last post by:
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...
5
by: Mike Dee | last post by:
Is it possible to dynamically create a new form object (form1), then create a new form field object and add it form1, and then add form1 to the current document? I need to do all this in script...
8
by: Nathan Sokalski | last post by:
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...
2
by: ajayreddy2105 | last post by:
Hi All, I want to build the xpath expression dynamically in the xsl for for-each. Scenario is like this:: 1. From javascript I am sending the parameters to xsl. 2. In xsl I am taking those...
3
by: rajachezhian | last post by:
hello, i am new to javascript. i want to use DIV object for expand/collapse the Tree Dynamically like Microsoft explorerer.MY size of the tree elements are changeing Dynamically. I need some...
6
by: _Who | last post by:
I use the code below to change to a style sheet that has: body { ....
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.