iJared iJared - 2 months ago 16
ASP.NET (C#) Question

ASP.NET Hyperlink control not render href on ascx webpart

I have a Hyperlink control on an .ascx that looks like this:

<asp:HyperLink ID="hDocument" NavigateUrl="http://www.google.com" Text="Delegate Approval" Target="_blank" runat="server"></asp:HyperLink>

However, when I navigate to my SharePoint page where this URL is supposed to be displayed, the hyperlink is not clickable and there is no href in the HTML anchor tag () like so:

<a id="ctl00_ctl40_g_65ace0cb_fdf4_4d40_ae31_9736b2d39022_gvLevel1Approvals_ctl02_hDocument" target="_blank">Delegate Approval</a>

I place a normal HTML anchor under the Hyperlink control and that one works fine. I have no idea why the Hyperlink control doesn't produce a href attribute when it renders.


Here's the original code:

<asp:HyperLink ID="hDocument" runat="server"></asp:HyperLink>

code behind

HyperLink hDocument = (HyperLink)e.Row.FindControl("hDocument");
hDocument.Text = "Delegate Approval";
hDocument.NavigateUrl = // builiding URL here;
hDocument.Target = "_blank";


So our situation with the was it would work only intermittently but 95% of the time it didn't work. Everything else worked fine: building the URL in the code behind, setting the link text, everything. We could not figure out why the href would not show up on the page on the client browser. In the end I eventually switched to using a regular HTML anchor tag and added in the System.Web.UI.HtmlControls namespace to find the anchor and modify that in the code behind.