title: Using HtmlAnchor or ASP.NET HyperLink for anchor tag that navigates in-page named anchor
body: <p>I am trying to render a simple hyperlink that links to a named anchor within the page, for example:</p>
  
  <pre><code>&lt;a href="#namedAnchor"&gt;scroll to down&lt;/a&gt;
  
  &lt;a name="namedAnchor"&gt;down&lt;/a&gt;
  </code></pre>
  
  <p>The problem is that when I use an ASP.NET control like <code>asp:HyperLink</code> or <code>HtmlAnchor</code>, the <code>href="#namedAnchor"</code> is rendered as <code>href="controls/#namedAnchor"</code> (where <code>controls</code> is the subdirectory where the user control containing the anchor is).  Here is the code for the control, using two types of anchor controls, which both have the same problem:</p>
  
  <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Test.ascx.cs" Inherits="TestWebApplication1.controls.Test" %&gt;
  
  &lt;a href="#namedAnchor" runat="server"&gt;HtmlAnchor&lt;/a&gt;
  
  &lt;asp:HyperLink NavigateUrl="#namedAnchor" runat="server"&gt;HyperLink&lt;/asp:HyperLink&gt;
  </code></pre>
  
  <p>The generated source looks like:</p>
  
  <pre><code>&lt;a href="controls/#namedAnchor"&gt;HtmlAnchor&lt;/a&gt;
  
  &lt;a href="controls/#namedAnchor"&gt;HyperLink&lt;/a&gt;
  </code></pre>
  
  <p>I really just want:</p>
  
  <pre><code>&lt;a href="#namedAnchor"&gt;HtmlAnchor&lt;/a&gt;
  
  &lt;a href="#namedAnchor"&gt;HyperLink&lt;/a&gt;
  </code></pre>
  
  <p>I am using the <code>HtmlAnchor</code> or <code>HyperLink</code> class because I want to make changes to other attributes in the code behind.  I do not want to introduce a custom web control for this requirement, as the requirement I'm pursuing is not that important enough to justify abandoning the traditional ASP.NET link controls.  It seems like I should be able to use the ASP.NET link controls to generate the desired link.</p>