Wednesday, 16 January 2013

ASP.NET MULTIPLE QUERY STRING

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:









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

No comments:

Post a Comment

Note: only a member of this blog may post a comment.