tags:

views:

323

answers:

1

So, I thought I'd try my luck on ASP.NET, didn't get very far before I found my first problem.

I have a Folder Layout like so:

\
->Admin
-->Admin.Aspx

->CSS
-->Style.css

->Images
-->bg.gif

Default.aspx
Default.master

Both admin.aspx and default.aspx use the default.master page, which contains the line:

<link rel="stylesheet" type="text/css" href="CSS/Style.css" media="screen" />

This works for the default.aspx page, because the path is valid, but for the admin page it's not.

Is there any special character, like ~ for home in linux, to indicate the root path. I can't use just a slash, cause the website maybe under a sub folder when hosted.

Hopefully I've explained myself so you can understand what I need to do :)

I guess it's more an html issue and than ASP issue..

+4  A: 

If your <head></head> tag contains runat="server" (which IIRC it does by default) you can simply specify it as:

<link rel="stylesheet" type="text/css" href="~/CSS/Style.css" media="screen" />
veggerby
Don't you need runat=server with the ~/ reference?
Jon Galloway
I seem to remember having seen that having it on the head tag is sufficient, but since you mention it I'll just try it out...
veggerby
Yes having it on head will do the trick:<head runat="server"> <link rel="stylesheet" type="text/css" href="~/CSS/Style.css" media="screen" /></head>yields:<head><link rel="stylesheet" type="text/css" href="../CSS/Style.css" media="screen" /></head>when my page is in a subfolder to the root
veggerby
Excellent, it works. But why does it work ? :)
PostMan
Wow, I didn't know having the head to be "runat=server" makes its child elements behave almost like server controls. Glad I read this answer.
o.k.w
Sure do :) same if you have <table runat="server"><tr><td></td></tr></table> your <tr> and <td> will get you a complete HtmlTable structure with HtmlTableRow's and HtmlTableCell's
veggerby