views:

176

answers:

2

This is what I'm adding and it renders the & as &

sharelink.Attributes.Add("addthis:url", "http://" & Request.Url.Host & "/Resources/PublicView.aspx?RID=" & R.ResourceID & "&Key=" & Key)

I need it to render this

?RID=64&Key=%2fwEUKwEDAgQCFAJA

instead of this

?RID=64&Key=%2fwEUKwEDAgQCFAJA
+2  A: 

Converting to & is correct, and the browsers should be able to handle it.

Source

To prove it, look at the source for this hyperlink.

EDIT: To explain, this is the correct way to do it. Writing <a href="a.com?b=c&d=e"> is wrong. Just like ASP.Net will use entities if you write <asp:Label runat="server" Text="><><" />, it will also use entities if you put an ampersand in an attribute.

SLaks
Middletone
SLaks
Middletone
SLaks
A: 

I post this comment as an answer due to limitation in commenting.

I agree with the answer by SLaks, this is especially so for strict XHTML compliance.

I've created a demo page with both & and &amp; which can be used for W3C validation.

See the demo page at http://74er.net/labs/amp-or-not.html and click on the bottom-most hyperlink to perform a w3c validation, or click here to validate directly.

The errors will be highlighted, all targetted at the line 14:

href="http://www.google.com/search?q=stackoverflow&amp;ie=UTF-8"

Whereas a similar one at line 19 with &amp; will pass:

href="http://www.google.com/search?q=stackoverflow&amp;amp;ie=UTF-8"
o.k.w