C# how to escape eval <%?
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")) %>
精彩评论