I am using ASP.NET tags in my markup an ASCX file.
<a id="MyId" runat="server" href="page.aspx?id=<%= Item.Id %>">View Item</a>
Item is a property in my control class in code behind.
However, the markup abov开发者_Go百科e is being rendered to the HTML unchanged, include the <%= %>
characters.
Does anyone have any idea why this might be?
Try removing the runat="server"
attribute from the anchor, like so:
<a href="<%= string.Format("{0}?id={1}", ResolveUrl("~/page.aspx"), item.Id) %>">
View Item
</a>
or use a HyperLink:
<asp:HyperLink ID="link" runat="server" NavigateUrl="~/page.aspx?id={0}">
View Item
</asp:HyperLink>
and in the code behind set the value:
link.NavigateUrl = string.Format(link.NavigateUrl, item.Id);
or using data binding syntax:
<asp:HyperLink ID="link" runat="server" NavigateUrl='<%# string.Format("~/page.aspx?id={0}", item.Id) %>'>
View Item
</asp:HyperLink>
and in the code behind call:
Page.DataBind();
精彩评论