Friday, January 15, 2010

Encode in JS Decode in C# problem

Just a quick one guys,

Recently we had a customer who complained about French tags that are not working with our tagging feature (field type, tag cloud for SP 2007 - pretty cool actually).

Well, apperantly we were doing some encoding of text in javascript using "escape()" and trying to decode it in C# on the server side using UrlDecode with no luck.

the text: "de l'entité" was not decoding correctly.

After trying to figure our whats wrong on the server side decoding function (I tried several alternatives) I almost gave up with no success whatsoever :(

So, I turned to look for alternatives in the Javascript encoding and found this new method called "encodeURI()". Apperantly this method can safely replace our "escape/unescape" in Javascript only it supports proper encoding and decoding with C# with no problems.

Works like a charm - from now on, use "encodeURI/decodeURI"!

Cheers, Shai.

3 comments:

Diego said...

Thank you so so much Shai! I was having the same problem & you gave me the answer! Encoding / Decoding may become pretty confusing when dealing with special characters, but your tip really helped me!

Thanks for posting this solution!!!

Anonymous said...

Thanks man, actually its saved my time :)

Anonymous said...

Thanks man, Actually it saved my time :)