Why is my inline asp.net not working in <link href>?

I want to add version number to my js files.

<link href="css/reset.min.css?v=<%= App.Golbal.VERSION %>" media="all" rel="Stylesheet" type="text/css" /> 

It displays as

 <link href="css/reset.min.css?v=&lt;%= App.Golbal.VERSION %>" media="all" rel="Stylesheet" type="text/css" /> 

[Standard asp.net 4 web application]

Does anyone help?

+6
web-applications versioning
source share
4 answers

Place it inside the PlaceHolder control because the link in the header is not included in the form tag, so it will not parse as shown below.

 <asp:PlaceHolder runat="server"> <link href="css/reset.min.css?v=<%= App.Golbal.VERSION %>" media="all" rel="Stylesheet" type="text/css" /> </asp:PlaceHolder> 
+8
source share

As Dante suggests above, maybe change

 <%= App.Golbal.VERSION %> 

to

 <%=App.Golbal.VERSION%> 

or

 <%=App.Global.VERSION%> 

and try this.

Alternatively, as William suggests, set id and runat = server in the link element and apply the value on the script / code server behind.

 <link id="lnkCSS" runat="server" media="all" rel="Stylesheet" type="text/css" /> 

and the script / code server behind, something like

 //might need HtmlLink lnkCSS = FindControls("lnkCSS")` lnkCSS.href = "css/reset.min.css?`v=" + App.Global.VERSION; 
+2
source share

I had similar problems before getting around this: make the asp: hyperlink and create the link in the code behind, and then assign the link to the NavigateURL hyperlink.

+1
source share

Can you try to remove the empty space in "<% = App.Golbal"? Btw, Global is wrong :)

0
source share

All Articles