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 :)