Click here to Skip to main content
16,012,316 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to pass an array in query string?
Posted
Comments
Amir Mahfoozi 12-Dec-11 7:07am    
Please explain more.

try this
1.aspx

ArrayList arr = new ArrayList();
arr.Add("file1″);
arr.Add("file2″);
arr.Add("file3″);
string arry = String.Join(",", ((string[])arr.ToArray(typeof(String))));
Response.Redirect("1.aspx?file=" + arry);

2.aspx

string[] files = Request["file"].ToString().Split(‘,’);
ArrayList arry = new ArrayList();
foreach (string file in files)
{
arry.Add(file);
}


another way

1.aspx

ArrayList arr = new ArrayList();
arr.Insert(0, "file1″);
arr.Insert(1, "file2″);
arr.Insert(2, "file3″);
Cache["test"] = arr;
arr = null;
Response.Redirect("2.aspx");

2.aspx

ArrayList ary = new ArrayList();
ary.Add(Cache["test"]);
Cache.Remove("test");
 
Share this answer
 
v2
I think you cannot pass Array or any other Objects through Query string except string values. Rather you can use Session Variable.

Try this..

In page One.

C#
//Set
Session["Variable"] = ArrayObj;


In page Two.

C#
//If String[]

string[] arry = (string[])Session["Variable"];

hope it helps..
 
Share this answer
 
You can't.
Query sting support only Plain text transformation. Query string allows a limited amount of data and also which is not secure, second thing at the receiving page you will get data as a string which is not your actual datatype of the object.

use Session, Cookies instead.

OR

You need to put your array in singlr string separated by any delimiter. and then pass it through Query string.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900