views:

275

answers:

3

So I have a Hyperlink called lnkTwitter:

And I'm trying to set the url in the code behind:

lnkTwitter.NavigateUrl = string.Format("http://www.twitter.com/home?status={0}", Server.UrlEncode("I'm Steven"));

When I do that and hover over the link, the url displays correctly in the status bar as "http://www.twitter.com/home?status=I'm+Steven", but the actual url, if I click on the link or look at the link's properties, is "http://www.twitter.com/home?status=I%27m+Steven".

For some reason, this only happens in Firefox; in IE, I am taken to the correct url.

+1  A: 

Have you tried to view source code? If source is ok, then there's no troubles with your code.

Vitaly Dyatlov
I checked the source code, and the href url contains the apostrophe in it instead of the code.What does that mean?
Steven
Hm.. then something's wrong with your code. Check this link:http://www.4guysfromrolla.com/demos/Server.UrlEncode.asp
Vitaly Dyatlov
A: 

Firefox just likes to unescape the urls that it shows. While this can be confusing it should not cause your code or the sites you link to (twitter, in this case) any problems.

If you follow the link and then copy the url and paste it into Notepad or something then you should get the escaped form that was actually used instead of the unescaped form that was displayed.

Journey
A: 

Uri.EscapeDataString, Uri.EscapeUriString, HttpUtility.UrlEncode and HttpUtility.UrlPathEncode are available to use in C# out of the box, they can not convert all the characters exactly the same way as JavaScript escape function does.

Solution: Use JScript.Net's own implementation. Simply reference the Microsoft.JScript.dll and use the Microsoft.JScript.GlobalObject.escape() method to encode your url.

Caesar