Reputation: 4202
I'd like to have a user populate a dataset using ASP.NET webforms. In a desktop application, I would simply use a dictionary data structure to keep track of the key/value pairs. I quickly learned that the dictionary object does not persist between page loads. How can I keep track of the user's existing data between page submissions?
Upvotes: 0
Views: 33
Reputation: 19220
Store in it the session. You need to configure this in the web.config and consider the different modes.
By default ASP.NET will persist user specific data in memory on the server. This doesn't scale unless using sticky IP on a load balancer. Alternatives are SessionState (a dedicated session state server), or Sql Server (database).
// store
Session["someData"] = objectToStore;
// retrieve
ObjectToStore objectToStore = (Session["someData"] as ObjectToStore);
Alternatively if you mean between page requests to the same page. Then you could use ViewState, which serializes the data into the page and reloads on Postback
. This means you only hit the database on the first request.
It's worth reading up on the different state mechanisms to figure out which is best for you.
Upvotes: 3