D
Dean Brettle
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" %>
<html>
<head></head>
<body>
<a runat="server" href='http://www.google.com/search?hl=en&q=test'
href2='http://www.google.com/search?hl=en&q=test'>HtmlAnchor</a>
<asp:HyperLink runat="server"
NavigateUrl='http://www.google.com/search?hl=en&q=test'
NavigateUrl2='http://www.google.com/search?hl=en&q=test'
Text='HyperLink' />
</body>
</html>
That renders as:
<html>
<head></head>
<body>
<a href="http://www.google.com/search?hl=en&q=test"
href2="http://www.google.com/search?hl=en&q=test">HtmlAnchor</a>
<a NavigateUrl2="http://www.google.com/search?hl=en&q=test"
href="http://www.google.com/search?hl=en&q=test">HyperLink</a>
</body>
</html>
Note that all of the ampersands *except* the one in the first "href"
attribute are HTML encoded (ie become "&")
--Dean
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" %>
<html>
<head></head>
<body>
<a runat="server" href='http://www.google.com/search?hl=en&q=test'
href2='http://www.google.com/search?hl=en&q=test'>HtmlAnchor</a>
<asp:HyperLink runat="server"
NavigateUrl='http://www.google.com/search?hl=en&q=test'
NavigateUrl2='http://www.google.com/search?hl=en&q=test'
Text='HyperLink' />
</body>
</html>
That renders as:
<html>
<head></head>
<body>
<a href="http://www.google.com/search?hl=en&q=test"
href2="http://www.google.com/search?hl=en&q=test">HtmlAnchor</a>
<a NavigateUrl2="http://www.google.com/search?hl=en&q=test"
href="http://www.google.com/search?hl=en&q=test">HyperLink</a>
</body>
</html>
Note that all of the ampersands *except* the one in the first "href"
attribute are HTML encoded (ie become "&")
--Dean