开发者

ASP.net c# make hyperlink point to page anchor

开发者 https://www.devze.com 2023-02-27 11:25 出处:网络
// Post quote GDQ.CssClass = \"s comment-quote\"; GDQ.ToolTip = \"Quote this post\"; GDQ.NavigateUrl = \"#Post\";
// Post quote
GDQ.CssClass = "s comment-quote";
GDQ.ToolTip = "Quote this post";
GDQ.NavigateUrl = "#Post";

And on my page I have:

<a name="Post"></a>

However, this url points to:

http://127.0.0.1/Site/Controls/#Post

Which is the path that the user control is in, I need it to jump to the #Post on whatever page the control exists on.

I can do:

GDQ.NavigateUrl = Page.Request.Url +  "#Post";

But the URL开发者_运维问答 I am on is rewritten, which points it to the actual filename which sends a new request. I just want it to jump on the current page.


This looks like it fixes it: Using HtmlAnchor or ASP.NET HyperLink for anchor tag that navigates in-page named anchor

So, in your case:

GDQ.Attributes["href"] = "#Post";


First the anchor has no name attribute, I think you wanted to write href instead of name

0

精彩评论

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