473,382 Members | 1,717 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,382 software developers and data experts.

Linking to a stylesheet multiple times

I have user controls that contain a link to a stylesheet. Several of my
pages also have a link to this same stylesheet. Because of this, the
resulting output contains multiple links to the same stylesheet. Although
this does not cause any harm as far as how the page looks, it is unnecessary
and makes the download take slightly longer. Is there any easy way to avoid
having the same stylesheet link added multiple times? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 19 '05 #1
7 1559
Nathan Sokalski wrote:
I have user controls that contain a link to a stylesheet. Several of
my pages also have a link to this same stylesheet. Because of this,
the resulting output contains multiple links to the same stylesheet.
Although this does not cause any harm as far as how the page looks,
it is unnecessary and makes the download take slightly longer. Is
there any easy way to avoid having the same stylesheet link added
multiple times? Thanks.


Why not just remove the style sheet link from your user control?

--
Jim Cheshire
JIMCO Software
http://www.jimcosoftware.com

FrontPage add-ins for FrontPage 2000 - 2003


Nov 19 '05 #2
If I removed the stylesheet link from my user control, I would need to
manually add it to any page I decided to add the control to. This somewhat
destroys the purpose of a user control (a control is supposed to be able to
be added without the need to add any other components). Also, doing this
would make it harder for me to edit the control in the future because the
control would be using code (the stylesheet) that is not referenced in the
control's code. Is there any way to do something like programmatically add
the stylesheet to a collection that is a property of the containing Page or
something like that?
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"JIMCO Software" <co*******@jimcosoftware.com> wrote in message
news:ud****************@TK2MSFTNGP10.phx.gbl...
Nathan Sokalski wrote:
I have user controls that contain a link to a stylesheet. Several of
my pages also have a link to this same stylesheet. Because of this,
the resulting output contains multiple links to the same stylesheet.
Although this does not cause any harm as far as how the page looks,
it is unnecessary and makes the download take slightly longer. Is
there any easy way to avoid having the same stylesheet link added
multiple times? Thanks.


Why not just remove the style sheet link from your user control?

--
Jim Cheshire
JIMCO Software
http://www.jimcosoftware.com

FrontPage add-ins for FrontPage 2000 - 2003

Nov 19 '05 #3
Nathan Sokalski wrote:
If I removed the stylesheet link from my user control, I would need to
manually add it to any page I decided to add the control to. This
somewhat destroys the purpose of a user control (a control is
supposed to be able to be added without the need to add any other
components). Also, doing this would make it harder for me to edit the
control in the future because the control would be using code (the
stylesheet) that is not referenced in the control's code. Is there
any way to do something like programmatically add the stylesheet to a
collection that is a property of the containing Page or something
like that?


I must have missed the word "several" in your original post.

What about using the runat attribute for your <link> tag so that you can
programmatically configure it?

--
Jim Cheshire
JIMCO Software
http://www.jimcosoftware.com

FrontPage add-ins for FrontPage 2000 - 2003


Nov 19 '05 #4
How exactly do you mean? I know how to use HtmlGenericControl controls, but
I am not quite sure what you had in mind as far as an algorithm. If you
could explain in more detail what you had in mind, I would appreciate it.
Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"JIMCO Software" <co*******@jimcosoftware.com> wrote in message
news:uJ**************@TK2MSFTNGP12.phx.gbl...
Nathan Sokalski wrote:
If I removed the stylesheet link from my user control, I would need to
manually add it to any page I decided to add the control to. This
somewhat destroys the purpose of a user control (a control is
supposed to be able to be added without the need to add any other
components). Also, doing this would make it harder for me to edit the
control in the future because the control would be using code (the
stylesheet) that is not referenced in the control's code. Is there
any way to do something like programmatically add the stylesheet to a
collection that is a property of the containing Page or something
like that?


I must have missed the word "several" in your original post.

What about using the runat attribute for your <link> tag so that you can
programmatically configure it?

--
Jim Cheshire
JIMCO Software
http://www.jimcosoftware.com

FrontPage add-ins for FrontPage 2000 - 2003

Nov 19 '05 #5
One possibility is to not declare the link. Instead, have a Literal control
where the link would go, and then set it's .Text property in your
code-behind. Your code behind could use whatever logic makes sense in your
application and that logic could insert the link when necessary otherwise
insert nothing. If your page's code-behind is aware of the asxc that it will
be hosting, that "knowledge" could be used to know when to insert the link
and when to not insert it (as just one way to go about this).

//This goes in your aspx <HEAD>:
<asp:Literal id="litCSSFileName" EnableViewState="False"
runat="server"></asp:Literal>

//Then you Page_Load logic could conditionally do something like this:
litCSSFileName.Text = strCssLink;

//Resulting in something like this at runtime in place of the Literal
declaration:
<LINK href="/MyApp/SubFolder/MyCssFile.css" type="text/css"
rel="stylesheet">

-HTH
BTW: It's considered bad etiquette to post same question to multiple news
groups.


"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:Ov**************@TK2MSFTNGP15.phx.gbl...
I have user controls that contain a link to a stylesheet. Several of my
pages also have a link to this same stylesheet. Because of this, the
resulting output contains multiple links to the same stylesheet. Although
this does not cause any harm as far as how the page looks, it is
unnecessary and makes the download take slightly longer. Is there any easy
way to avoid having the same stylesheet link added multiple times? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 19 '05 #6
Hi Nathan

You can use the Page.RegisterStartupScript() from the code behind with
the 'key' and then check to see if scripts (or in this case, styles)
with the same key have already been registered.

eg.

if(!Page.IsStartupScriptRegistered("mycss"))
{
Page.RegisterStartupScript("mycss",@"<style type=""text/css""
src=""styles.css""></style>");
}

Nov 19 '05 #7
Nathan Sokalski wrote:
How exactly do you mean? I know how to use HtmlGenericControl
controls, but I am not quite sure what you had in mind as far as an
algorithm. If you could explain in more detail what you had in mind,
I would appreciate it. Thanks.


In your HTML, add something along the lines of this:

<link id="_ctlLink" runat="server" rel="stylesheet" type="text/css" />

Then in your code-behind, do this after your class declaration.

protected System.Web.UI.HtmlControls.HtmlGenericControl _ctlLink;

Now you can add code like this to Page_Load to set the stylesheet:

_ctlLink.Attributes.Add("href", "styles.css");

You can now programmatically control when and what stylesheet gets applied.

--
Jim Cheshire
JIMCO Software
http://www.jimcosoftware.com

FrontPage add-ins for FrontPage 2000 - 2003


Nov 19 '05 #8

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

Similar topics

3
by: Sarah Haskins | last post by:
I have a few questions about this problem I'm having involving XML, DTD, and XSL. I'm working with this DTD which defines a stylesheet, as such... <?xml version="1.0" encoding="UTF-8"?>...
3
by: Headless | last post by:
Should linking generated content work? Example: span:before{content:"foobar"} <a href="foobar.htm"><span></span></a> I stumbled across this bit in the CSS2 spec: >Generated content does...
2
by: Jan Roland Eriksson | last post by:
Archive-name: www/stylesheets/authoring-faq Posting-Frequency: twice a week (Mondays and Thursdays) Last-modified: August 28, 2002 Version: 1.15 URL: http://css.nu/faq/ciwas-aFAQ.html...
3
by: Jamie | last post by:
Hi, Thanks for the excellent answer to my last question! One more: Does anyone have a method they follow for organizing stylesheets themselves? They seem like they can get bloated and hard to...
0
by: Jan Roland Eriksson | last post by:
Archive-name: www/stylesheets/authoring-faq Posting-Frequency: twice a week (Mondays and Thursdays) Last-modified: April 10, 2003 Version: 1.16 URL: http://css.nu/faq/ciwas-aFAQ.html Maintainer:...
5
by: Don G | last post by:
Is it possible to link multiple stylesheets to a single web page? I have an overall stylesheet for my entire site, but there are a few pages with a minor differences. I originally had these as...
6
by: Rudy Ray Moore | last post by:
I work with a multi-project workspace. One project (the "startup" project) has a "Configuration Type" of "Application (.exe)". The other 40 projects have a "Configuration Type" of "Static Library...
9
by: gkountz | last post by:
Hi: I am brand new to css and a have a limited amount of working knowledge regarding HTMl. This is primarily from using Frontpage. I recently purchased Stylemaster, a css authoring program,...
6
by: _Who | last post by:
I use the code below to change to a style sheet that has: body { ....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.