Tuesday, October 12, 2010

Sending multiple Query String with ASP.NET Page

Passing Multiple Querystring values with Response.Redirect method

Here's an example on how to pass Multiple querystrings in the page..

Page1

protected void Button1_Click(object sender, EventArgs e)
{
        string strName = "Ram";
        string strAddress = "Chennai";
        string strDate = DateTime.Now.ToShortDateString();
        Response.Redirect(string.Format("TestNasad2.aspx?param1={0}&param2={1}&param3={2}",strName,strAddress,strDate));


The on Page2 you can get each values this way below


protected void Page_Load(object sender, EventArgs e)
{
        if ((Request.QueryString["param1"] != null && Request.QueryString["param2"] != null) && Request.QueryString["param3"] != null)
        {
            string name = Request.QueryString["param1"];
            string address = Request.QueryString["param2"];
            string date = Request.QueryString["param3"];

        }
}


Hope this Helps!

Another Example:


Passing multiple parameters to a Query String in ASP.NET
 
When you need to send multiple QueryString Parameters to a Webpage you can follow this:    

//arguments Declaration              
int styear=1980;
int endyear=1989;
string country="India"; 

//Forming a Query String
string url = String.Format("detail.aspx?startYear={0}&endYear={1}&country={3}", styear, endyear, type, country);

//Sending Query String
Reponse.Redirect(url);



If want to use more querystring parameter you need to pass Arguments (ex:"&country={3}",country); like this you can pass any number of query string i will work fine.

OUTPUT: 


Response.Redirect("detail.aspx?startYear=1980&endYear=1989&country=India");


No comments:

Post a Comment