referencing to style sheet

D

David C

I am not fully understanding how to refer to another file in the aspx
page.

There is one style sheet which I need to refer to and it is in the root
directory

<LINK href="styles.css" type="text/css" rel="stylesheet">

So how to I refer to that from aspx pages in various sub-directories?
It works if I use relative paths (../styles.css), but not if you are
going to the aspx file from another aspx file from a different
directory.

Tried ~/styles.css hoping that the reference will work no matter where,
but it does not work.
 
A

Alec MacLean

David,

You can add further relative pathing;

/folder_with_css_file
|
- sub-folder
|
-sub-sub-folder

With aspx page in "sub-sub-folder", you would extend your realtive path
navigation to add another parent folder directive (../), like this;

<LINK href="../../styles.css" type="text/css" rel="stylesheet">
^^

Hope that helps

Al
 
J

Josh Twist

In order for ASP.NET to resolve the ~/styles.css the element must be a
server control:

<link href="styles.css" type="text/css" rel="stylesheet" runat="server"
/>

I don't think this works in ASP.NET 1.x though, but this does:

<link href="<%=Page.ResolveUrl("~/styles.css")%>" type="text/css"
rel="stylesheet" />

Josh
http://www.thejoyofcode.com/
 
D

David C

It works....Thanks...BUT, got a big problem. Once I do that to a page, it
does not let me add a literal control to the page any more, and it shows the
following error message.

The Controls collection cannot be modified because the control contains code
blocks (i.e. <% ... %>).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top