asp.net user control, getting htmlAnchor resolve to href="#"
asp.net, c#, user-controls
Solution
I had the same problem, here's how I could resolve it:
Original code
User control:
<a id="foo" runat="server">...</a>
Code behind:
foo.Attributes.Add("href", "#");
Output:
<a id="..." href="../Shared/Controls/#">...</a>
Updated code
User control:
<asp:HyperLink id="foo" runat="server">...</asp:HyperLink>
Code behind:
foo.Attributes.Add("href", "#");
Output:
<a id="..." href="#">...</a>
Problem
How do you get a server control HTMLAnchor to have href="#". It keeps resolving the "#" to the control path. ``` <a href="#" runat="server" /> resolves to: <a href="../ControlPath/#"> ``` I can't seem to get a google search to give me the results i want so i figured i'd ask here. EDIT: Syntax. Removing the runat server is not an option. It's manipulated in the backend, this was just a simplification.