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 %>" />
6
  • 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: w3schools.com/tags/tag_link.asp Commented Dec 10, 2013 at 14:41
  • the rel doesn't make a difference to the server rending the variable Commented Dec 10, 2013 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. Commented Dec 10, 2013 at 14:44
  • 1
    Fair point David, updated question with html output Commented Dec 10, 2013 at 14:48
  • 1
    Great, now we can fix this for you! Please refer to this for fix: stackoverflow.com/questions/5603086/… Commented Dec 10, 2013 at 14:52

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Dave, this pointed me to a slightly different answer, but one that worked!
NP - I found the link valuable because it had the REASON why your original code did not work as well as a solution! Happy coding!
2

Hie Gordon,

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

Difference between SRC and HREF

Thanks!

1 Comment

hmmmmm i see. Is there a way I can add a dynamic query string to a href then?
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) %>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.