Thursday, 20 March 2014

how to read query string in asp.net

Many times we need to pass the data from browser, from one page to another page in that case we need to use the query string.


1.       Send data from query string.
Just add the parameter at the last of the url. Suppose you are using response.redirect than
       Response.Redirect("default.aspx?param=1"); //where param=1 is query string


2.       To receive data from query string.          


a.       Read data from query string.
string v = Request.QueryString["param"];
                    if (v != null)
                    {
                        Response.Write("param is ");
                        Response.Write(v);
                    }

b.      Another way to read query string is;
Uri RealURL = new Uri(HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.RawUrl);
                    string yourValue = HttpUtility.ParseQueryString(RealURL.Query).Get("Param");

No comments:

Post a Comment

Others

You will like to read it