Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Using ~/ path for to link a CSS page?

Reply
Thread Tools

Using ~/ path for to link a CSS page?

 
 
Lance Wynn
Guest
Posts: n/a
 
      01-17-2008
Hello all,
Is there a way to use the ~/ path to link a CSS page?

I thought maybe something like this would work, but no go:
<link href="~/style.css" rel="stylesheet" type="text/css"/>

Is this possible to do with the link element?

Thanks


 
Reply With Quote
 
 
 
 
Cowboy \(Gregory A. Beamer\)
Guest
Posts: n/a
 
      01-17-2008
~ is filled in by a routine in WebControl (GetClientPath() I think. If not,
it is close). The link is not attached to a control. YOu can code your own
implementation of link that use the routine to covnert ~. Otherwise, you
cannot use ~ to represent route.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
"Lance Wynn" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello all,
> Is there a way to use the ~/ path to link a CSS page?
>
> I thought maybe something like this would work, but no go:
> <link href="~/style.css" rel="stylesheet" type="text/css"/>
>
> Is this possible to do with the link element?
>
> Thanks
>



 
Reply With Quote
 
 
 
 
Jialiang Ge [MSFT]
Guest
Posts: n/a
 
      01-17-2008
Hello,

From your post, my understanding on this issue is: you wonder how to
resolve the root directory when we link to a style sheet. If I'm off base,
please feel free to let me know.

According to the MSDN article: ASP.NET Web Site Paths
http://msdn2.microsoft.com/en-us/library/ms178116.aspx
"ASP.NET includes the Web application root operator (~), which you can use
when specifying a path in *server controls*. ASP.NET resolves the ~
operator to the root of the current application. You can use the ~ operator
in conjunction with folders to specify a path that is based on the current
root."
Therefore, as Cowboy replied, the link is not attached to a server control,
and the operator '~' cannot be resolved as expected.

Here are two workarounds for your reference:

Workaround 1: Declare 'runat=server' for the <head> element, and use '~'
inside it. For instance,
<head runat="server">
<title>Untitled Page</title>
<link href="~/Css/style.css" rel="stylesheet" type="text/css" />
</head>

Workaround 2:
We can link to the style sheet with some server side codes
(quoted from
http://www.pluralsight.com/blogs/ted.../31/14437.aspx)
public static void AddLinkedStyleSheet(Page page, string stylesheet)
{
HtmlLink link = new HtmlLink();
link.Href = page.ResolveUrl(stylesheet);
link1.Attributes["text"] = "text/css";
link1.Attributes["rel"] = "stylesheet";

page.Header.Controls.Add(link);
}
MyClass.AddLinkedStyleSheet(this, "~/css/my.css");

Please let me know if you have any other concerns, or need anything else.

Regards,
Jialiang Ge ((E-Mail Removed), remove 'online.')
Microsoft Online Community Support

==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
marss
Guest
Posts: n/a
 
      01-17-2008
On 17 Січ, 05:08, "Lance Wynn" <(E-Mail Removed)> wrote:
> Hello all,
> Is there a way to use the ~/ path to link a CSS page?
>
> I thought maybe something like this would work, but no go:
> <link href="~/style.css" rel="stylesheet" type="text/css"/>
>


If you use href="/style.css" it refers to a stylesheet resided in the
root folder of an application
disregarding of position of the parent page in a website hierarchy.
IMHO, no need to convert the stylesheet link to a server control, a
leading slash "/" for HTML elements do the same as "~/" for web/HTML
controls.

Regards,
Mykola
http://marss.co.ua - Casual ideas for web development
 
Reply With Quote
 
John
Guest
Posts: n/a
 
      01-17-2008
Just to add, if you're refering to Master pages then a Link tag within the
Head section gets resolved before being combined with its content page so
"style.css" should work in your case (also link tags within conditional
comments - thanks Steven). I've just read "ASP.Net 2.0 - Master Pages:
Tips, Tricks, and Traps" by K. Scott Allen
(http://odetocode.com/Articles/450.aspx) which is a great article on the
subject.

Hope that helps.

Best regards

John

"Lance Wynn" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello all,
> Is there a way to use the ~/ path to link a CSS page?
>
> I thought maybe something like this would work, but no go:
> <link href="~/style.css" rel="stylesheet" type="text/css"/>
>
> Is this possible to do with the link element?
>
> Thanks
>



 
Reply With Quote
 
Leon Mayne
Guest
Posts: n/a
 
      01-17-2008
"Lance Wynn" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello all,
> Is there a way to use the ~/ path to link a CSS page?
>
> I thought maybe something like this would work, but no go:
> <link href="~/style.css" rel="stylesheet" type="text/css"/>
>
> Is this possible to do with the link element?


Adding runat="server" should do it:
<link href="~/style.css" rel="stylesheet" type="text/css" runat="server" />


 
Reply With Quote
 
Hans Kesting
Guest
Posts: n/a
 
      01-17-2008
marss brought next idea :
> On 17 Січ, 05:08, "Lance Wynn" <(E-Mail Removed)> wrote:
>> Hello all,
>> Is there a way to use the ~/ path to link a CSS page?
>>
>> I thought maybe something like this would work, but no go:
>> <link href="~/style.css" rel="stylesheet" type="text/css"/>
>>

>
> If you use href="/style.css" it refers to a stylesheet resided in the
> root folder of an application
> disregarding of position of the parent page in a website hierarchy.
> IMHO, no need to convert the stylesheet link to a server control, a
> leading slash "/" for HTML elements do the same as "~/" for web/HTML
> controls.
>
> Regards,
> Mykola
> http://marss.co.ua - Casual ideas for web development


That will work for a production server where the root of the
application is http://www.company.com.
It will fail on your development box where you want to use
http://localhost/CompanyDevSite

The ~ syntax (when used correctly) will work in both cases.

Hans Kesting


 
Reply With Quote
 
marss
Guest
Posts: n/a
 
      01-17-2008
On 17 Січ, 11:44, Hans Kesting <(E-Mail Removed)> wrote:

> It will fail on your development box where you want to usehttp://localhost/CompanyDevSite


You are right, I completely forgot this aspect.
Perhaps, I became too spoilt by VS 2005 using http://localhost:1720/
instead of http://localhost/MySite/

Regards,
Mykola
http://marss.co.ua - Casual ideas of web development
 
Reply With Quote
 
Patrice
Guest
Posts: n/a
 
      01-17-2008
Another option is to place the stylesheet in the site theme folder. It will
be then automatically referenced from your pages...

--
Patrice

"Lance Wynn" <(E-Mail Removed)> a crit dans le message de news:
http://www.velocityreviews.com/forums/(E-Mail Removed)...
> Hello all,
> Is there a way to use the ~/ path to link a CSS page?
>
> I thought maybe something like this would work, but no go:
> <link href="~/style.css" rel="stylesheet" type="text/css"/>
>
> Is this possible to do with the link element?
>
> Thanks
>



 
Reply With Quote
 
Tahir
Guest
Posts: n/a
 
      01-17-2008
hi,

here is some code from my MasterPage:
......
<body>
<form id="form1" runat="server">

<div id="main-header" class="box">
<img src="Tema/banner.bmp" alt=""/>
......

i have a "Tema" folder at root directory containing MasterPage and
banner.bmp.
* when i use this code, VS indicates that banner file is missing but at
debug time web browser shows the image, the result is ok.
* when i write there ="~/Tema/banner.bmp", VS says ok but browser says image
missing where it shows the address "localhost/website/~/Tema/banner.bmp"
* when i show the image by vs gui, the code apperas as
src="../Tema/banner.bmp", image is still missing and browser shows the
address "localhost/Tema/banner.bmp"

can anybody who understands the "~" operator, describes this?


"Lance Wynn" <(E-Mail Removed)>, iletisinde unu yazd,
news:(E-Mail Removed)...
> Hello all,
> Is there a way to use the ~/ path to link a CSS page?
>
> I thought maybe something like this would work, but no go:
> <link href="~/style.css" rel="stylesheet" type="text/css"/>
>
> Is this possible to do with the link element?
>
> Thanks
>


 
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
Problem setting css style using relative path PeterKellner ASP .Net 2 07-30-2006 10:01 PM
RE: Link Link Link =?Utf-8?B?REw=?= Windows 64bit 0 05-17-2005 12:15 PM
Re: Link Link Link DANGER WILL ROBINSON!!! Kevin Spencer ASP .Net 0 05-17-2005 10:41 AM
Compiling when libedit is in path Is there a trick to compiling Ruby when libedit must exist in the search path? Can you statically link to readline 5.0 in some manner? -- Lon Baker Lon Baker Ruby 1 03-21-2005 08:57 AM
Tomcat returning 404 error when using additional path (/servlet/myServlet/extra/path/info) Mupota Muchelemba Java 1 02-04-2004 12:43 AM



Advertisments