开发者

ASP.NET Tags not Being Converted

开发者 https://www.devze.com 2023-03-18 04:27 出处:网络
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>

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();
0

精彩评论

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