473,406 Members | 2,894 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,406 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 1218
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...
1
by: JezB | last post by:
How can I dynamically change an external stylesheet link (or import) at runtime in server-side code ? I don't want to use a placeholder as in <link id="myTheme" rel="stylesheet"...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.