views:

448

answers:

4

In my web application I have a number of custom grids on a page. I want the user to be able to edit data in each grid and then press save once at the end of the process to commit their changes.

So I need somewhere temporary to persist their changes before they are comitted. The grids will use AJAX/Javascript so as to not force a full page refresh when data is edited

I can think of the following options for storing temporary data

  1. Hidden form fields
  2. ViewState
  3. Session

The option I'm least comfortable with is the ViewState option as I have read that this is being phased out in ASP.NET 4.0 and am not sure if you can access ViewState from an AJAX page method.

I'm interested in peoples opinions on the above options and also if ViewState should be used for storing data that is not related to out of the box controls.

+2  A: 

ViewState is not being phased out, and never will be.

However, you're right that you can't access it in a static page method.

I recommend that you store the data in the session.

SLaks
+3  A: 

ASP.Net 4.0 isn't phasing out ViewState (it's pretty central to how web forms work!), it's just slightly altering how ViewState works by default. You can read about it here.

If you want to manually track the data, then the best option is Session. But ViewState is meant for saving these kinds of temporary changes for you automatically.

womp
+1  A: 

Hey,

From a server-side technology, session/cache is your best bet; session is user-specific while cache is application-specific, but you can store items in the cache with a key that has the user id appended to it so that it becomes user specific.

On the client-side, you have to use hidden fields to store data because JavaScript doesn't know about session/cache, and AJAX requests don't necessarily have access to certain web resources. You can try to access these resources through HttpContext.Current in a web request, but information about the page wouldn't be available in a Web Service call or PageMethods web service call.

Brian
A: 

As has been said, store it in session but make sure to clean up when you're done and only store what you really need to store, i.e., don't just dump a bunch of stuff in session because it's easy.

We use session fairly heavily in our app but make sure to clean up after ourselves and only keep what we really need. You can run into performance issues if you use session as a dumping ground.

Chuck