I am using Web Forms Routing in ASP.NET 4 and I am trying to route to a specific location on a page. On that page I have an element like <div id="3">
and I'd like to jump to this anchor from another page. For this purpose I have defined a Route in global.asax
:
RouteTable.Routes.MapPageRoute("MyRoute", "Path/SubPath/{PageAnchor}",
"~/MyPage.aspx", true, new RouteValueDictionary { { "PageAnchor", null } });
The HyperLink to link to that page and the anchor "3" is defined this way in markup:
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="<%$ RouteUrl:RouteName=MyRoute,PageAnchor=#3 %>">
Link</asp:HyperLink>
The problem with the generated link is that the #
character in the URL gets encoded by %23
this way: http://localhost:1234/Path/SubPath/%233
so that I reach the target page but not at the specified anchor.
Is there a way to avoid this unwished URL-encoding? Or any other way to route to an anchor?
Thank you in advance!