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

how do you reference relative CSS files from the link attribute?

I'm having a problem using the tilde in a relative path reference in my
aspx. Has anyone got any tips'n'tricks?

Right now the resolved html is this.
<link id="cssLink" rel="stylesheet" href="~/Resources/main.css"
type="text/css"></link>

It doesn't want to resolve the ~ in the href. Any ideas?
Nov 18 '05 #1
9 1680
I believe tilde (~) works only for server controls & user controls?

"Flip" <[remove]ph******@hotmail.com> wrote in message
news:#M**************@TK2MSFTNGP10.phx.gbl...
I'm having a problem using the tilde in a relative path reference in my
aspx. Has anyone got any tips'n'tricks?

Right now the resolved html is this.
<link id="cssLink" rel="stylesheet" href="~/Resources/main.css"
type="text/css"></link>

It doesn't want to resolve the ~ in the href. Any ideas?

Nov 18 '05 #2
Howdy. Thanks for the quick response.
I believe tilde (~) works only for server controls & user controls?

I thought if I put the runat="server" then that would make it a server
control and it would evaluate it. But does this not work in the <HEAD>
tags?
Nov 18 '05 #3
No. AFAIK, it only works for 'real' controls.

"Flip" <[remove]ph******@hotmail.com> wrote in message
news:#P**************@TK2MSFTNGP09.phx.gbl...
Howdy. Thanks for the quick response.
I believe tilde (~) works only for server controls & user controls?

I thought if I put the runat="server" then that would make it a server
control and it would evaluate it. But does this not work in the <HEAD>
tags?

Nov 18 '05 #4
> No. AFAIK, it only works for 'real' controls.
How do you handle the relative references in your pages for CSSs?
Nov 18 '05 #5
You can add a placeholder control to your page in the header, then in
the code behind for the page you can call a routine that generates the
css information, puts it in a literal control, then adds the literal
control to the place holder. When you get to the point where you want
to construct the relative path all you should need to do is run it
through the ResolveUrl method of the page object and it will resolve it
to the proper location. You could create a routine that takes the place
holder and the relative path as parameters then put that somewhere easy
to get to (a base page perhaps) so you don't have to think about it
again. Hope that helps/gives you enough information to move forward with.

Have A Better One!

John M Deal, MCP
Necessity Software

Flip wrote:
No. AFAIK, it only works for 'real' controls.


How do you handle the relative references in your pages for CSSs?

Nov 18 '05 #6
Hello Flip,

In your code behind...

string link = String.Format("<link id='cssLink' rel='stylesheet' href='{0}'
type='text/css'></link>", Page.ResolveUrl("~/Resources/main.css"));
Page.RegisterStartupScript("css", link);

Granted, this will not put it in the head section... but that shouldnt be
a problem.

--
Matt Berther
http://www.mattberther.com
I'm having a problem using the tilde in a relative path reference in
my aspx. Has anyone got any tips'n'tricks?

Right now the resolved html is this.
<link id="cssLink" rel="stylesheet" href="~/Resources/main.css"
type="text/css"></link>
It doesn't want to resolve the ~ in the href. Any ideas?

Nov 18 '05 #7
while all unix webservers support the "~/", IIS support is spotty.
asp.net support consists of rewriting the url at render time. this is only
for Web.UI.WebControls.

-- bruce (sqlwork.com)

"Flip" <[remove]ph******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
| I'm having a problem using the tilde in a relative path reference in my
| aspx. Has anyone got any tips'n'tricks?
|
| Right now the resolved html is this.
| <link id="cssLink" rel="stylesheet" href="~/Resources/main.css"
| type="text/css"></link>
|
| It doesn't want to resolve the ~ in the href. Any ideas?
|
|
Nov 18 '05 #8
Thank you Shiva, John, Matt and Bruce for replying. I'm going to try the
suggestions tonight/tomorrow night. Thanks again! :>
Nov 18 '05 #9
> while all unix webservers support the "~/", IIS support is spotty.
You bring up a good question. I'm coming from j2ee on both linux and win
servers where I used "/" for path separators. What are we supposed to use
in aspx? I've seen both, but the unix style a bit more, is that what we're
supposed to use?

Thanks.
Nov 18 '05 #10

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

Similar topics

3
by: allard poldermans | last post by:
How can I make a reference to an external CSS or JS file that is relative to the XSL stylesheet, and not relative to the XML data? If you simply put : <link rel="stylesheet" type="text/css"...
12
by: Jean-Yves Simon | last post by:
Hi, I have a little problem and I was hoping that someone could help me. I have installed on my PC, the server web apache. Eveything works fine and I have started to create some pages. In...
7
by: Rizaan Jappie | last post by:
is it possible to get the relative path based on a absolute path in c#? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
2
by: Steve Franks | last post by:
I am familiar with the fact that you have to use runat=server and links staring with "~/" to ensure proper mapping of paths to relative URLs when using master pages. However this does not seem to...
18
by: Nak | last post by:
Hi there, Does anyone know what path the AssemblyKeyFile attribute is relative to? For example I currently have mine set to <Assembly: AssemblyKeyFile("..\NicksKey.snk")> Sometimes this...
5
by: druberego | last post by:
I read google and tried to find the solution myself. YES I do know that you can get undefined references if you: a) forget to implement the code for a prototype/header file item, or b) you forget...
12
by: Alan Isaac | last post by:
Are relative imports broken in 2.5? Directory ``temp`` contains:: __init__.py test1.py test2.py File contents: __init__.py and test2.py are empty test1.py contains a single line::
5
shishisu
by: shishisu | last post by:
I figure this might be a fun challenge to some of you out there... I appreciate all the help. Thanks in advance. Here we go... I have 2 web page (on different servers) I am working on. Here,...
1
by: =?Utf-8?B?bWFya203NQ==?= | last post by:
There is probably some simple answer to my question, but i'm still new to this a bit.. I have a master page.. with a menu system which is coded onto the masterpage.aspx... it uses A tags with...
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:
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.