Get HyperLink's NavigateURL property as just “#myhashtag”
سؤال
I have a user control with a hyperlink control within it. The application is database driven (it's kentico).
I need set to set the hyperlink's navigateurl property to #section-1. When I do so, asp.net is converting the user to /myfolder/usercontrols/#section-1. That's not even the URL that was in the browser, and breaks some existing javascript code I'm working with.
How can I easily get the hyperlink's navigateurl property to render as a clean "#section-1"?
Yes, I need a server side control.
If I build the full request URL manually, even with "~/...", asp.net renders it as a server relative URL, when I just want a clean href="#section-1".
المحلول
Have you tried:
HyperLink1.Attributes.Add("href","#section-1")
or
HyperLink1.Attributes("href") = "#section-1" 'overwrite any existing href
نصائح أخرى
How about:
hypTheLink.NavigateUrl = Request.Url.PathAndQuery + "#JumpMark";
لا تنتمي إلى StackOverflow