Encoding / decoding URL's

I was caught up in the web created by HTML /Javascript/ ASP.NET due to a very common problem related to URL encoding. For my current project I had to call a popup from an aspx page using client side code written in Javascript. Everything worked fine untill a day came where there was a special character to be passed in the query string.
The special character which was to be passed was '&' and that also happens to be a a special character for query string to seperate different values. My initial thinking was that javascript's good old escape function would do the job for me. But escape does encoding only for spaces and +. The '&' is left as it is because it's a valid character for escape sequence.
After doing few rounds of google I came across two functions which did the job for me. One of them is encodeURI and the one which I used was encoreURIComponent.
Please refer following article for further reading W3schools.com article.

Once the values were encoded correctly on client side it was only a matter of using the capabilities of Server side coding and decoding it back to its original value. Server.HtmlDecode does the job without any fuss.

Hope this is of some help. Happy programming :)