Store list in Viewstate

Asked

Viewed 723 times

0

I want to assemble a list of strings and save it to a viewstate, and use it later. Ex

List<string> listaNomes = new List<string>();
foreach(var algo in TesteList)
{
listaNomes.add(algo.id);
//salve essa lista em ViewState
}

I’m saving several strings on this list, but I need to manipulate it elsewhere on the page,?

1 answer

0


If you want to use this information on another page you should use the session and not the viewState, Viewstate keeps the information only on the page you are on.

Use Session as follows.

Assigning List to Session.

List<string> listaNomes = new List<string>();

    listaNomes.Add("Marconi");
    listaNomes.Add("Marcos");

    Session["Lista"] = listaNomes;

Recovering the Session list on another page or on the same page.

List<string> lista = (List<string>)Session["Lista"];

If you no longer need to use you can remove the session item.

Session.Remove("Lista");
  • it worked out vlw...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.