Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > referencing to style sheet

Reply
Thread Tools

referencing to style sheet

 
 
David C
Guest
Posts: n/a
 
      02-05-2006


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.

*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
Alec MacLean
Guest
Posts: n/a
 
      02-05-2006
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


"David C" <(E-Mail Removed)> wrote in message
news:eBa%(E-Mail Removed)...
>
>
> 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.
>
> *** Sent via Developersdex http://www.developersdex.com ***



 
Reply With Quote
 
 
 
 
Josh Twist
Guest
Posts: n/a
 
      02-05-2006
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/

 
Reply With Quote
 
David C
Guest
Posts: n/a
 
      02-05-2006
I DO NOT want to have to use relative paths, so this one will not work.

"Alec MacLean" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
> "David C" <(E-Mail Removed)> wrote in message
> news:eBa%(E-Mail Removed)...
>>
>>
>> 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.
>>
>> *** Sent via Developersdex http://www.developersdex.com ***

>
>



 
Reply With Quote
 
David C
Guest
Posts: n/a
 
      02-05-2006
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. <% ... %>).

"Josh Twist" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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/
>



 
Reply With Quote
 
Josh Twist
Guest
Posts: n/a
 
      02-06-2006
Hmm... you could put that code into a user control and place the user
control on each page instead of the <link> element itself.

Josh
http://www.thejoyofcode.com/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
style sheet referencing itself? Joseph Kesselman XML 2 03-20-2008 11:46 PM
Content Page specific style style sheet rshillington@gmail.com ASP .Net 0 07-14-2006 03:45 PM
Firefox screwing with my style sheet margins! Bill Firefox 14 11-18-2005 03:30 PM
Need help with Style conversion from Style object to Style key/value collection. Ken Varn ASP .Net Building Controls 0 04-26-2004 07:06 PM
Adding style sheet dynamicaly Marc Nederhoff ASP .Net 2 11-05-2003 04:56 PM



Advertisments