<% = doesn't want to print in css element

When using a link element, asp does not process <% = CssVersion%>, but interprets it as a literal string

  <link href="../../css/style01.css?<%= CssVersion %>" rel="stylesheet" type="text/css"> 

output above:

 <link type="text/css" rel="stylesheet" href="../../css/style01.css?<%= CssVersion >"> 

But when is it used

 <script language="javascript" src="../../js/tiutil_1.0.js?<%= CssVersion %>" type="text/javascript"></script> 

Then it will print correctly as

 <script type="text/javascript" src="../../js/tiutil_1.0.js?220409" language="javascript"></script> 

Any idea why?

thanks

+4
source share
2 answers

I do not understand why this behavior, but I found an alternative solution

 <link <%="href='../../css/style01.css?" + CssVersion + "'"%> rel="stylesheet" type="text/css" /> 
+1
source

Tim B James has a decision; you need to set the runat='server' control before you can use those replacement tags (<% =%>).

Another solution not recommended for your situation is to register a javascript variable from the server:

Client side:

 <link href="../../css/style01.css?" +jvCSSVersion+ """ rel="stylesheet" type="text/css"> 

Server side:

  Page.ClientScript.RegisterStartupScript(getType(Page), "scrJV", "var jvCSSVersion = '" + CssVersion + "';", true); 
+2
source

All Articles