Using ~/ path for to link a CSS page?

Using ~/ path for to link a CSS page?

am 17.01.2008 04:08:06 von Lance Wynn

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:


Is this possible to do with the link element?

Thanks

Re: Using ~/ path for to link a CSS page?

am 17.01.2008 04:31:33 von NoSpamMgbworld

~ 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" wrote in message
news:OSukvYLWIHA.4904@TK2MSFTNGP06.phx.gbl...
> 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:
>
>
> Is this possible to do with the link element?
>
> Thanks
>

Re: Using ~/ path for to link a CSS page?

am 17.01.2008 05:58:37 von jialge

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 element, and use '~'
inside it. For instance,

Untitled Page



Workaround 2:
We can link to the style sheet with some server side codes
(quoted from
http://www.pluralsight.com/blogs/ted/archive/2005/08/31/1443 7.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 (jialge@online.microsoft.com, 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/subscriptions/managednewsgroups/de fault.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/subscriptions/support/default.aspx .
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Re: Using ~/ path for to link a CSS page?

am 17.01.2008 07:04:44 von marss

On 17 Січ, 05:08, "Lance Wynn" =
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:
>
>

If you use href=3D"/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

Re: Using ~/ path for to link a CSS page?

am 17.01.2008 08:22:46 von John

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" wrote in message
news:OSukvYLWIHA.4904@TK2MSFTNGP06.phx.gbl...
> 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:
>
>
> Is this possible to do with the link element?
>
> Thanks
>

Re: Using ~/ path for to link a CSS page?

am 17.01.2008 09:43:01 von Leon Mayne

"Lance Wynn" wrote in message
news:OSukvYLWIHA.4904@TK2MSFTNGP06.phx.gbl...
> 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:
>
>
> Is this possible to do with the link element?

Adding runat="server" should do it:

Re: Using ~/ path for to link a CSS page?

am 17.01.2008 10:44:22 von Hans Kesting

marss brought next idea :
> On 17 Січ, 05:08, "Lance Wynn" 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:
>>
>>
>
> 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

Re: Using ~/ path for to link a CSS page?

am 17.01.2008 12:01:01 von marss

On 17 Січ, 11:44, Hans Kesting m> 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

Re: Using ~/ path for to link a CSS page?

am 17.01.2008 13:22:17 von Patrice

Another option is to place the stylesheet in the site theme folder. It will
be then automatically referenced from your pages...

--
Patrice

"Lance Wynn" a écrit dans le message de news:
OSukvYLWIHA.4904@TK2MSFTNGP06.phx.gbl...
> 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:
>
>
> Is this possible to do with the link element?
>
> Thanks
>

a problem with ~/

am 17.01.2008 13:36:10 von Tahir

hi,

here is some code from my MasterPage:
......





......

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" , iletisinde þunu yazdý,
news:OSukvYLWIHA.4904@TK2MSFTNGP06.phx.gbl...
> 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:
>
>
> Is this possible to do with the link element?
>
> Thanks
>

Re: a problem with ~/

am 17.01.2008 13:48:17 von mark

"Tahir" wrote in message
news:etClQWQWIHA.4712@TK2MSFTNGP04.phx.gbl...

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

The tilde (~) is server-side notation, not client-side notation...

That is why something like: can never
work...

However, will work...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Re: Using ~/ path for to link a CSS page?

am 18.01.2008 00:28:00 von mily242

Howdy,

Workaround 4:
" type="text/css" />
ResolveClientUrl method is invented for such purposes.
--
Milosz


"Jialiang Ge [MSFT]" wrote:

> 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 element, and use '~'
> inside it. For instance,
>
> Untitled Page
>
>
>
> Workaround 2:
> We can link to the style sheet with some server side codes
> (quoted from
> http://www.pluralsight.com/blogs/ted/archive/2005/08/31/1443 7.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 (jialge@online.microsoft.com, 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/subscriptions/managednewsgroups/de fault.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/subscriptions/support/default.aspx .
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>

Re: Using ~/ path for to link a CSS page?

am 21.01.2008 03:41:20 von jialge

Hello,

Would you mind letting me know the result of the suggestions? If you need
further assistance, feel free to let me know. I will be more than happy to
be of assistance.

Have a great day!

Regards,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Re: Using ~/ path for to link a CSS page?

am 21.01.2008 05:03:17 von Lance Wynn

Sorry it took so long to get back to you, My wife went into labor, and I've
been at the hospital until today. (Healthy boy, 11 lbs 13 oz aprox 5.3
kilos, he is huge ;-)

I was able to get it working using the runat=server in the tag, I
have not been able to try any of the other suggestions, but I certainly
learned a lot more about ASP.net through this.

Thanks alot,
Lance



"Jialiang Ge [MSFT]" wrote in message
news:lufvjc9WIHA.6404@TK2MSFTNGHUB02.phx.gbl...
> Hello,
>
> Would you mind letting me know the result of the suggestions? If you need
> further assistance, feel free to let me know. I will be more than happy to
> be of assistance.
>
> Have a great day!
>
> Regards,
> Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
>
> =================================================
> When responding to posts, please "Reply to Group" via your newsreader
> so that others may learn and benefit from your issue.
> =================================================
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>

Re: Using ~/ path for to link a CSS page?

am 22.01.2008 06:15:45 von jialge

Hello Lance,

I'm very pleased to hear the good news. Congratulations! : )

Regards,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Re: Using ~/ path for to link a CSS page?

am 22.01.2008 13:16:17 von gustaf.lindqvist

On Jan 21, 5:03=A0am, "Lance Wynn" wrote:
> Sorry it took so long to get back to you, My wife went into labor, and I'v=
e
> been at the hospital until today. =A0(Healthy boy, 11 lbs 13 oz aprox 5.3
> kilos, he is huge ;-)
>
> I was able to get it working using the runat=3Dserver in the tag, I=

> have not been able to try any of the other suggestions, but I certainly
> learned a lot more about ASP.net through this.
>
> Thanks alot,
> Lance
>
> "Jialiang Ge [MSFT]" wrote in messagenews:lu=
fvjc9WIHA.6404@TK2MSFTNGHUB02.phx.gbl...
>
>
>
> > Hello,
>
> > Would you mind letting me know the result of the suggestions? If you nee=
d
> > further assistance, feel free to let me know. I will be more than happy =
to
> > be of assistance.
>
> > Have a great day!
>
> > Regards,
> > Jialiang Ge =A0(jia...@online.microsoft.com, remove 'online.')
> > Microsoft Online Community Support
>
> > ==================== =====
==================== =====3D
> > When responding to posts, please "Reply to Group" via your newsreader
> > so that others may learn and benefit from your issue.
> > ==================== =====
==================== =====3D
> > This posting is provided "AS IS" with no warranties, and confers no
> > rights.- Hide quoted text -
>
> - Show quoted text -

That solution should work. If you don't wan't runat on the head tag
you could add only "runat" on the link tag.

This should also work, I think.


type=3D"text/css" runat=3D"server" />


Regards,
Gustaf Lindqvist

Re: Using ~/ path for to link a CSS page?

am 22.01.2008 17:13:29 von Lance Wynn

I thought this should work too, but it didn't. Apparently the link tag
doesn't accept the runat=server parameter

"G.Lindqvist" wrote in message
news:d70d533f-dd96-4b6b-a3c9-b7f3dab52c6d@f10g2000hsf.google groups.com...

That solution should work. If you don't wan't runat on the head tag
you could add only "runat" on the link tag.

This should also work, I think.


type="text/css" runat="server" />


Regards,
Gustaf Lindqvist

Re: Using ~/ path for to link a CSS page?

am 23.01.2008 04:59:19 von Lance Wynn

Thanks Patrice,
I started studying about themes, skins, and dynamically setting the master
page, and I am really liking where things are going. I think this will solve
a lot of my ills.

Thanks again for the helpful nudge!

"Patrice" wrote in message
news:O7rMbOQWIHA.4904@TK2MSFTNGP06.phx.gbl...
> Another option is to place the stylesheet in the site theme folder. It
> will be then automatically referenced from your pages...
>
> --
> Patrice
>
> "Lance Wynn" a écrit dans le message de
> news: OSukvYLWIHA.4904@TK2MSFTNGP06.phx.gbl...
>> 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:
>>
>>
>> Is this possible to do with the link element?
>>
>> Thanks
>>
>
>