October 12, 2006

Attributes.Add Lameness

Had some trouble today with *.Attributes.Add and using an ampersand &.

The problem is Attributes.Add and here's what I found:

Using Reflector to trace through System.Web.UI.WebControlsWebControl.Attributes to see if it was doing any kind of encoding turns out that
System.Web.HttpUtility.HtmlAttributeEncode is called on any text added via Attributes.Add. HtmlAttributeEncode turns & into & and turns double quotes (") into "
Lameness I say! Anyways the solution I used was to register a startup script and place my onClick in a function then on my attributes.add I just call the javascript function. Works well, and note that this happened to me on ASP.NET 1.1, not sure if it occurs in 2.0

kick it on DotNetKicks.com

kick it on DotNetKicks.com

No comments: