开发者

Why does my inline asp.net not working within <link href>?

开发者 https://www.devze.com 2023-02-15 16:22 出处:网络
I want to add a version number to my js files. <link href=\"css/reset.min.css?v=<%= App.Golbal.VERSION %>\" media=\"all\" rel=\"Stylesheet\" type=\"text/css\" />

I want to add a version number to my js files.

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

This renders as

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

[Standard asp.net 4 web applciation]

Can anybody help?


Put it inside PlaceHolder control because link in the title not included in the form tag so no parsing will occur to it as following

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


As Dante suggests above, maybe change

<%= App.Golbal.VERSION %>

to

<%=App.Golbal.VERSION%>

or

<%=App.Global.VERSION%>

and try that.

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

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

and the server script/code behind, something like

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


I've had similar issues before the way to get around it is make the link an asp:hyperlink and build the link in the code behind and then assign the link to the NavigateURL of the hyperlink.


Can you try removing the white space in "<%= App.Golbal"? Btw, Global is mispelled :)

0

精彩评论

暂无评论...
验证码 换一张
取 消