Ways to store an object across multiple postbacks
asp.net, entity-framework, postback
Solution
If using the Session is not your preferred solution, which is probably wise, the best possible solution would be to create your own temporary database tables (or as others have mentioned, add a temporary flag to your existing database tables) and persist the data there, storing a single identifier in the Session (or in a cookie) for later retrieval.
Problem
For the sake of argument assume that I have a webform that allows a user to edit order details. User can perform the following functions: - Change shipping/payment details (all simple text/dropdowns) - Add/Remove/Edit products in the order - this is done with a grid - Add/Remove attachments Products and attachments are stored in separate DB tables with foreign key to the order. Entity Framework (4.0) is used as ORM. I want to allow the users to make whatever changes they want to the order and only when they hit 'Save' do I want to commit the changes to the database. This is not a problem with textboxes/checkboxes etc. as I can just rely on ViewState to get the required information. However the grid is presenting a much larger problem for me as I can't figure out a nice and easy way to persist the changes the user made without committing the changes to the database. Storing the Order object tree in Session/ViewState is not really an option I'd like to go with as the objects could get very large. So the question is - how can I go about preserving the changes the user made until ready to 'Save'. Quick note - I have searched SO to try to find a solution, however all I found were suggestions to use Session and/or ViewState - both of which I would rather not use due to potential size of my object trees