0

Inside my GridView I have this:

<asp:TemplateField HeaderText="Issue">
    <ItemTemplate>
        <asp:HyperLink ID="EscalationHyperlink" runat="server" NavigateUrl='<%# EscalationGetNavigateUrl(Eval("ID")) %>' Text='<%# Eval("ID") %>'>
        </asp:HyperLink>
     </ItemTemplate>
</asp:TemplateField>

It won't show a hyperlink in the resulting GridView. The "Text" value is correct, it's just not a hyperlink. This GridView is embedded in an UpdatePanel and is being generated by the user pushing a button.

If I set a breakpoint inside EscalationGetNavigateUrl() it trips when the button is pressed, and it returns the correctly formatted hyperlink, which is weird.

To make matters more interesting, I have this exact markup all over the place and it seems to work fine on other pages, just not this one.

Any ideas on where I might be going wrong (or a better way to debug it)? It's like the generated value from the code-behind just isn't making it to the browser somehow.

The code-behind looks like this:

protected string EscalationGetNavigateUrl(object field)
{
     return String.Format("~/EscalationDetails.aspx?EscalationId={0}", field);
}

EDIT: I already said this in the comments below, but I wanted to add some output that's returned from the server. It looks like this:

<a id="MainContent_ClosedCREscGridView_EscalationHyperlink_0">175</a>

You'll notice there is no href on the link.

4
  • 1
    By "not a hyperlink" do you mean that ASP.NET does not Render an anchor (A) element? What does the markup look like (view source)? Does something set Enabled=false? IIRC disabled ASP:HyperLink controls will Render as plaintext instead of as links. (er wait,maybe they just render disabled=disabled so the browser doesn't act on it like a link.. anyway, check the markup after render and post the resulting HTML please. Commented Nov 19, 2014 at 20:18
  • Here is what one of the fields, that should be a hyperlink, looks like (I had to capture the AJAX response): <a id="MainContent_ClosedCREscGridView_EscalationHyperlink_0">175</a> There's no href! Ha ha ha! Why would there be no href??? Commented Nov 19, 2014 at 21:32
  • 1
    Have you tried to set the NavigateUrl ins the RowDataBound event? Commented Nov 19, 2014 at 21:41
  • [RE: cpacheco] This does not work either as another column in my gridview does exactly this - parses some data and creates a hyperlink. Looks like all NavigateUrl attributes are broke on this page for some reason. Commented Nov 19, 2014 at 21:55

2 Answers 2

1

After many hours with a bottle of whiskey and a loaded revolver sitting in front of me, I figured out the problem. Here is the answer:

ClosedCREscGridView.Enabled = true;

It is NOT sufficient to just have the GridView "Visible." You have to also have it "Enabled" for the HyperLink NavigateURL functionality to work inside a GridView TemplateField.

Hope this saves someone else some time in the future.

Sign up to request clarification or add additional context in comments.

Comments

0

That is an odd one but you are lucky that it works on other pages because you can compare the working vs non working pages to find a difference. For example, do they both use DataView?, do they both use asp:TemplateField?, are they both generated via updatepanel / callback (as opposed to first load/postback)? etc.

A couple other things to try:

1) Add a asp:HyperLink control to the page that is NOT part of an update panel and is not in a template/dataview and make sure it renders OK.

2) Try to force the hyperlink by using the href attribute directly instead of going through NavigateUrl, for example:

<asp:TemplateField HeaderText="Issue">
    <ItemTemplate>
        <asp:HyperLink ID="EscalationHyperlink" runat="server" href='<%# EscalationGetNavigateUrl(Eval("ID")) %>' Text='<%# Eval("ID") %>'>
        </asp:HyperLink>
     </ItemTemplate>
</asp:TemplateField>

3) If you don't really need the hyperlink to be a server control (you probably don't since it is dynamic), you could try to render the HTML directly like this:

<asp:TemplateField HeaderText="Issue">
    <ItemTemplate>
        <a href='<%# EscalationGetNavigateUrl(Eval("ID")) %>'><%# Eval("ID") %></a>
     </ItemTemplate>
</asp:TemplateField>

Admittedly #3 is not an ideal solution because it should just work, but it may give you other results to compare to that could help identify the reason for this erratic behavior on this one page.

Concerning debugging: you could put a breakpoint in the DataView's RowDataBound handler, set the NavigateUrl, and then test whether it was actually set. If that looks good, then you could also stub in some GetCallbackResult and Unload handlers, set a breakpoint in each, and check the NavigateUrl values from within those.

3 Comments

RE #1: Adding a asp:HyperLink inside or outside of the UpdatePanel works fine. RE #2: Forcing the href inside the asp:HyperLink works. RE #3: Using a <a /> tag intead of the asp:HyperLink works. I also set a breakpoint inside of my Unload() routine. This was interesting as the asp:Hyperlink I created inside my OnRowDataBound() handler was classified as a asp:HyperLink, and had the correct NavigateUrl, but it didn't render as one. My asp:Hyperlink controls I set INSIDE my GridView were classified as literal controls (and had no NavigateUrl).
Another thing: If I completely gut the page of EVERYTHING except the GridView (and bind data to it in PageLoad()), it still doesn't work.
That's a pretty weird inconsistency.. unfortunately I can't be much more help without seeing the full code for the page (both codebehind and markup). Only final thought is: have you tried it on a different box? Maybe you need a .NET update or hotfix or something.. probably not the cause, but without seeing your code I can only speculate. Your best tool in the meantime is to compare all aspects of non-working page with a working page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.