> I am trying to create an anchor tag on a page that look like this:
>
> <a id="some_id" onSomeAction="this.href='page.aspx?a=1&b=2'">some_ text</a>
>
> I tried to accomplish this using System.Web.UI.WebControls.LinkButton object
> and using the following statement:
>
> linkbutton.Attributes ["onSomeAction"] = "this.href='page.aspx?a=1&b=2'";
>
> When run, the '&' character gets translated to '&' . As a result, the
> output on the page looks like this:
>
> <a id="some_id"
> onSomeAction="this.href='page.aspx?a=1&b=2'">s ome_text</a>
I used Reflector to look at the code for the AttributeCollection's
Render() method. Essentially, it loops through the added attributes,
and does a writer.WriteAttribute(...) call, passing in the key and value
of the attribute, where writer is an HtmlTextWriter instance.
Now, here's the rub. The HtmlTextWriter's WriteAttribute() method takes
in as a third parameter a Boolean indicating whether or not the HTML
passed in should be HTML encoded. The AttributeCollection's Render()
method, unfortunately, passes in a hard-coded value of true.
There may be an elegant workaround, but I can't think of one off the top
of my head. Sorry!
--
Scott Mitchell
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com
* When you think ASP, think 4GuysFromRolla.com!