C# - Cant dynamically set url of css file but can in vb.net??

  • Thread starter Thread starter Richard Coltrane
  • Start date Start date
R

Richard Coltrane

Hi There,

Does anyone know iwhy I can do this in VB.Net:

<link rel="stylesheet" href="<%=Global_asax.GetApplicationPath()
%>styles/main.css" type="text/css">

in the header of an aspx page and not have a problem. i.e it converts nicely
but when i do it in c# it always converts the first "<" to ="&lt and thus
becomes

<link rel="stylesheet" href="&lt;% = MaranuiGlobal.GetApplicationPath()
%>styles/main.css" type="text/css" />

which in turn is not interpreted by the asp.net engine. Note this doesn;t
happen in the source file and is not a problem with the designer. It occurs
at runtime.
And yet as with vb.net this kind of statement in interpreted correctly for
all other tags including refs to javascript files. Its just with CSS/link
tags???

Thanks
 
Please ignore difference in method name in the second statement:

<link rel="stylesheet" href="="&lt;%=Global_asax.GetApplicationPath()

I copy pasted the wrong code. This is not the problem.

Thanks


%>styles/main.css" type="text/css">
 
Try using ResolveClientUrl instead ie.
<link rel="stylesheet" href="<%=ResolveClientUrl("~/styles/main.css")%>"
type="text/css">
 
Back
Top