Search code examples
asp.netviewstate

How to save Array in View State? And Retrieve That in ASP.NET?


I am using Asp.Net With JqueryMobile (C#). I declare string[] roomno = new string[100]; in my Class.

In Page_load Event:-

if (!Page.IsPostBack)
{
    Some Code...
     for (int j = 0; j <= vallen; j++)
     {
         roomno[j] = "A" + Convert.ToString(j + 1);
     }
    Some Code,..
}

When I Click The Button The Array values is clear. So I wanna know How to save Array in View State? And Retrieve That in ASP.NET?


Solution

  • ViewState["some_key"] = roomno;
    
    roomno = ViewState["some_key"] as string[];
    

    or words to that effect :)