Why doesn't a link in a HyperLinkField render?

written by Ryan Olshan on Thursday, January 26 2006

It appears that there is a security feature built-in to the HyperLinkField that causes links that resemble JavaScript functions (i.e. java script:SomeFunction()), file paths (i.e. F:\Directory\File), and other non-URL strings not to render when using the DataNavigateUrlFormatString property. The only way I've discovered around this is to use a TemplateField with a HyperLink control.

Will not render a URL:

<asp:HyperLinkField DataTextField="SomeField" DataNavigateUrlFields="SomeField"
DataNavigateUrlFormatString="java script:openWindow('/SomePage.aspx?SomeID={0}','SomeDescription','scrollbars=yes,width=442,height=500');" />

Will render a URL:

<asp:TemplateField>
   
<ItemTemplate
>
      
<asp:HyperLink Text='<%# ((System.Data.DataRowView)Container.DataItem)["SomeField"] %>' NavigateUrl='<%# String.Format("java script:openWindow('/SomePage.aspx?SomeID={0}','SomeDescription','scrollbars=yes,width=442,height=500');", ((System.Data.DataRowView)Container.DataItem)["SomeField"] as string) %>' runat="server"
/>
   
</ItemTemplate
>
</asp:TemplateField>

Similar Posts

  1. VB.NET GridView Sorting/Paging w/o a DataSourceControl DataSource
  2. New Modules Installed
  3. Snap and Community Server

Post a comment