Thursday, November 10, 2011

Best way to pass multiple query string value from one page to another page with Response.Redirect method

In most of the cases developers need to pass more than one or multiple query string value from one page to another page. Here in this example i will show you how one can pass multiple values from one page to another page in an efficient way. Let I have a product row and want to send product data from one page to another page so the code will looks like:










01protected void Page_Load(object sender, EventArgs e)
02    {
03        if (!IsPostBack)
04        {
05            string sName = "Tibbet";
06            string sBrand = "Kohinoor";
07            string sDescription = "For menz only";
08            Response.Redirect(string.Format("Default.aspx?qs1={0}&qs2={1}&qs3={2}", sName, sBrand, sDescription));
09        }
10    }
From second page we can read the value like:
01protected void Page_Load(object sender, EventArgs e)
02    {
03        if (!IsPostBack)
04        {
05            if ((Request.QueryString["qs1"] != null && Request.QueryString["qs2"] != null) && Request.QueryString["qs3"] != null)
06            {
07                string sName = Request.QueryString["qs1"];
08                string sBrand = Request.QueryString["qs2"];
09                string sDescription = Request.QueryString["qs3"];
10                Response.Write(sName+"</br>");
11                Response.Write(sBrand + "</br>");
12                Response.Write(sDescription);
13            }
14        }
15    }

No comments:

Post a Comment