Embedded code in NavigateUrl of an asp:Hyperlink. What am I doing wrong?
In code-behind of an ASP.NET page I have this method:
public string TestFunc()
{
return "http://www.blabla.net";
}
And in markup this:
<%= TestFunc() %>
If I run the page I see "http://www.blabla.net" as text on the page and in debugger I enter TestFunc - all as expected.
If I put this Hyperlink on the same aspx page...
<asp:HyperLink ID="MyLink" runat="server" NavigateUrl='<%= TestFunc() %>'>Proceed...
</asp:HyperLink>
... I don't enter TestFunc in debugger and the generated HTML of the href contains the embedded code simply as text: href="%3C%=%20TestFunc%28%29%20%%3E"
What am I doing wrong here? I have already tried stupid trial and error: Replaced =
开发者_运维百科by #
, omitted =
and replaced single quotation marks '
by double quotation marks "
. But all this didn't help. Now I am stumped.
Thanks for help in advance!
You can use "<% %>" construction within container which supports templates (e.g. GridView with combination of Bind, Eval). Simple usage with properties will cause encode your expression and will display "as is".
精彩评论