Urldecode QueryString Urldecode QueryString UrlDecode QueryString Many web developers assumes that, if QueryString parameter is in encoded format then it should be decoded before processing the data. This is really one of the wrong assumption. Here I will explain what's the correct way to deal with QueryString parameters.

Before passing the parameter to http web request, it has to be encoded. Otherwise, your request would get terminated.

Encodong of the parameter is done by HttpUtility.UrlEncode function. UrlDecode for QueryString parameter example.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class URLEncodeDemo : System.Web.UI.Page
  protected void Page_Load(object sender, EventArgs e)

    string math = Request.QueryString["result"];

    Response.Write("Output is: " + math);

"); Response.Write("Output using UrlDecode is: " + HttpUtility.UrlDecode(Request.QueryString["result"])); } protected void Button1_Click(object sender, EventArgs e) { Response.Redirect(Request.Url.ToString() + "?result=" + HttpUtility.UrlEncode("12+25")); } }

Output is: 12+25
Output using UrlDecode is: 12 25 

Description Here we are expecting to get "12+25", which is what we had passed as query string parameter. QueryString method itself decode the parameters, so you don't need to decode it explicitly.


asp net image uploadHow to Pass To Query String In Interview Questions for 2 years or 3 years File 2.0 step by step Membership Provider What is web garden in Convert Image To Convert String To open new windowHack asp.netListBox Binding csharp


My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.

I'm Satalaj.