Possible bug: HtmlAnchor HRef property is not HTML encoded

Discussion in 'ASP .Net Web Controls' started by Dean Brettle, Dec 28, 2005.

  1. Dean Brettle

    Dean Brettle Guest

    Hi all,

    At least under ASP.NET 2.0 (don't know about 1.1), the "href" property
    of an HtmlAnchor control is not HTML encoded Is this a bug or is it by
    design? If it is a bug, in which version is it expected to be fixed?

    FWIW, other attributes of the HtmlAnchor control are HTML encoded and
    the NavigateUrl property of the HyperLink control is also HTML encoded
    so the current behavior seems to be inconsistent. Here is a simple
    page to demonstrate:

    <%@ Page language="c#" AutoEventWireup="true"
    Inherits="System.Web.UI.Page" %>
    <a runat="server" href='http://www.google.com/search?hl=en&q=test'
    <asp:HyperLink runat="server"
    Text='HyperLink' />

    That renders as:

    <a href="http://www.google.com/search?hl=en&q=test"
    <a NavigateUrl2="http://www.google.com/search?hl=en&amp;q=test"

    Note that all of the ampersands *except* the one in the first "href"
    attribute are HTML encoded (ie become "&amp;")

    Dean Brettle, Dec 28, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.