开发者

C# how to escape eval <%?

开发者 https://www.devze.com 2023-02-03 17:38 出处:网络
I have such code: <%# (int)Eval(\"Favorites\") > 0 ? \"<a href=\\\"histor开发者_开发知识库y.aspx?visitorid=<%# Eval(\\\"VisitorID\\\") %\\\">Favorites</a> / \" : \"\"%>

I have such code:

<%# (int)Eval("Favorites") > 0 ? "<a href=\"histor开发者_开发知识库y.aspx?visitorid=<%# Eval(\"VisitorID\") %\">Favorites</a> / " : ""%>

where I show a link if value>0 .. However it gives me a bad url(history.aspx?visitorid=%3C%#%20Eval) when I put visitorID=<%#...%>inside another Eval<%#..%>

how to escape this? thanks


You could seperate that string, like this:

?visitorid=<" + "%# Eval(\"Visit


You can have the second Eval called if you code it like this:

<%# (int)Eval("Favorites") > 0 ? "<a href=\"history.aspx?visitorid=" + Eval("VisitorID") + "\">Favorites</a> / " : ""%>


As your strings get more complex, you'll find it's easier to build them using static methods in your code behind. Then in your ASPX you'll have something simple like <%# GetLink(Eval("VisitorId")) %>

0

精彩评论

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

关注公众号