1

Can anyone tell me why this works:

<script type="text/javascript" src="/js/jqFuncs.js?v=<%=jqFuncsScriptlastWriteTime %>" />

But this doesn't

<link type="text/css" rel="stylesheet" href="/css/site.css?v=<%=sitecsslastWriteTime %>" />

My code behind has:

public string jqFuncsScriptlastWriteTime = System.IO.File.GetLastWriteTime(@"c:/web/cs3/js/jqFuncs.js").ToString("yyMMdd");
public string sitecsslastWriteTime = System.IO.File.GetLastWriteTime(@"c:/web/cs3/css/site.css").ToString("yyMMdd");

The rendered HTML looks like this:

<script type="text/javascript" src="/js/jqFuncs.js?v=131126" ></script>
<link type="text/css" rel="stylesheet" href="/css/site.css?v=&lt;%=sitecsslastWriteTime %>" />
Gordon Copestake
  • 1,616
  • 4
  • 21
  • 37
  • could you try adding rel="stylesheet" on your link tag? not sure if it is required in all browsers. According to this, it is required: http://www.w3schools.com/tags/tag_link.asp – David Fleeman Dec 10 '13 at 14:41
  • the rel doesn't make a difference to the server rending the variable – Gordon Copestake Dec 10 '13 at 14:43
  • So this is a server side problem -- the variable is not written into the page? You should update your question instead of saying "it doesn't work". If it is not writing the expected variable value into the page on the server side, I would guess the file c:/web/cs3/css/site.css doesn't exist or you don't have access to it. – David Fleeman Dec 10 '13 at 14:44
  • What is your generated source @GordonCopestake ? – Eliezer Bernart Dec 10 '13 at 14:46
  • 1
    Fair point David, updated question with html output – Gordon Copestake Dec 10 '13 at 14:48
  • 1
    Great, now we can fix this for you! Please refer to this for fix: http://stackoverflow.com/questions/5603086/problem-in-expression-tag-to-bind-string-variable – David Fleeman Dec 10 '13 at 14:52

3 Answers3

2

Hie Gordon,

There are some differences between href and src. More details here:

Difference between SRC and HREF

Thanks!

Community
  • 1
  • 1
Eliezer Bernart
  • 2,386
  • 24
  • 33
2

The problem is caused by the way ASP.NET treats LINK tags. Here is another question/answer that provides the solution:

Problem in Expression tag to bind string variable

I would try adding runat="server" first on the link tag. If that does not work, then I would use the other solution that is the accepted answer.

Community
  • 1
  • 1
David Fleeman
  • 2,588
  • 14
  • 17
2

For anyone else searching for the answer i used this:

<%= String.Format("<link type=\"text/css\" rel=\"stylesheet\" href=\"/css/site.css?v={0}\" />", sitecsslastWriteTime) %>
Gordon Copestake
  • 1,616
  • 4
  • 21
  • 37