JavaScript, UTF-8 Encoding: escape() vs. encodeURIComponent()

ASP.Net web applications default to UTF-8 encoding.  Now, if you are using JavaScript to create or change URLs, you might run into an issue with the way the function “escape()” encodes characters if you are handling the decoding in your code behind via Request.QueryString.

To avoid ending up with “unkown” characters in your resultant string, use the JavaScript function “encodeURIComponent()” instead.  This should correctly encode your URLs for UTF-8.

 

 

This entry was posted in ASP.Net, C#, JavaScript. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *