1

I am using asp.NET with masterpages and usercontrols.

In MasterPage:

Doing

<link href='<%=ResolveUrl("~/path/file.css")%>' rel="stylesheet" type="text/css" />

will not work and the css will not load BUT

Doing

<link runat="server" href='~/path/file.css' rel="stylesheet" type="text/css" />

will work and the css will load

In User Control:

Doing

<link runat="server" href='~/path/file.css' rel="stylesheet" type="text/css" />

will not work and the css will not load

BUT

Doing

<link href='<%=ResolveUrl("~/path/file.css")%>' rel="stylesheet" type="text/css" />

will work and the css will load

In master page ResolveUrl doesn't work and runat="server" works where in user control the opposite is the true. Maybe I worng and I appriciate if someone will check this. If this is the situation, what is the reason for this inconsistency?

Tomas Jansson
  • 21,761
  • 10
  • 75
  • 128
Naor
  • 22,523
  • 46
  • 144
  • 260

2 Answers2

0

You can read here in details what is going on.

In short is so the '~' character is only for use at the server

Yacov
  • 1,038
  • 14
  • 26
0

Ok, I got it.
In one of the cases I had <head runat="server"> tag. Because the runat="server", the ResolveUrl is not act as a server method but a simple text. That is why ResolveUrl didn't word - I had runat="server" in the head tag.

Naor
  • 22,523
  • 46
  • 144
  • 260