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..


protected void Button1_Click(object sender, EventArgs e)
        string strName = "Ram";
        string strAddress = "Chennai";
        string strDate = DateTime.Now.ToShortDateString();

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

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.



No comments:

Post a Comment