Using HtmlAnchor or ASP.NET HyperLink for anchor tag that navigates in-page named anchor

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 03:12:40

Instead of using the NavigateUrl property, just use the href property

<asp:HyperLink href="#namedAnchor" runat="server">HyperLink</asp:HyperLink>

To set the HREF property in codebehind:

HyperLink link = new HyperLink();
link.Attributes.Add("href", "#" + doc.DocumentID.ToString());
link.Text = doc.DocumentNumber;

This will give you:

<a href="#111">blah blah</a>
Tom

Set it as a custom property on the link:

        HyperLink link = new HyperLink();
        link.Attributes.Add("name", doc.DocumentID.ToString());
        link.Text = doc.DocumentNumber;

This will give you:

<a name="111">blah blah</a>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!