Saturday, August 29, 2009

Pass Array List through Query string .

Last week i have faced a challange in my project. To pass a string array list throght query string while googlig i found no solution for this so i thought it will be help full to post my solution.

In Parent Page:

protected void Page_Load(object sender, EventArgs e)
{
string[] namesArray = {"Welcome", "To" ,"C#" , "World"};
string Params= String.Join(",", ((string[])namesArray.ToArray(typeof(String))));
Response.Redirect("Page2.aspx?items=" + Params);
}

In Child Page

protected void Page_Load(object sender, EventArgs e)
{
string[] Params= Request["Params"].ToString().Split(',');

foreach (string strNm in Params)
{
Response.Write(strNm);
}
}

No comments: