Maybe its a stupid question, but i'm having this issue in Visual Studio 2010:
in my Master page i've this code:
<head runat="server">
<title>App Title</title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<link href="<%= App.RootPath %>Css/style.css" rel="stylesheet" type="text/css" />
</head>
for some strange reason the <%
is changed at runtime with <%
<%= App.RootPath %>
works normal if put anywhere outside head tag.
Anyone has never experienced this and resolved?
UPDATE:
If i put off runat="server" in head tag, it works. But i need it.
Edit:
All of these methods work, but the problem is lack of designer support?
The explanation for your trick:
<link <%= "href='" +App.RootPath +"Css/style.css'" %> rel="stylesheet" type="text/css" />
To find the answer generate a compilation exception. Change App.RootPath
to App.RootPaths..
, then navigate to the source code (it will be shown in the error page). If the compiler matches something like <link href='' rel='' >
then it will generate the code to build a corresponding HtmlLink
instance. So this is why it parses <%=
as a literal string and after that it encodes it.
Your trick cheats the compiler, which is not bad at all.
I believe it does the same thing for meta tags, (HtmlMeta
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With