I have a user control, on load of which I have some data from the database. A user can manipulate the data in different ways (CRUD). The process of manipulating data can cause server side events or at the client side. Then there is a save button on the page that eventually processes the temporary data and writes it to the database.
I am looking for an elegant approach to this. My thinking is:
- On load, use a hidden variable and serialize data (at that point in a form of a custom datastructure) to JSON
- On any event (server side/client side) that manipulates the data, deserialize, perform the operation and serialze back to hidden variable
- On the final save, deserialize to the datastructure that it was first loaded as and hit the database
Since all this is happening in the ASCX.CS, I can't really use the cool OOP stuff (for polymorphism if in future they decide that these operations should not be done in temp storage but rather to the database)
I am pretty much stuck with an approach of a class having a bunch of static methods that has one method for each of these operations. In the code behind, I will have to serialize/deserialze data as and when there are events that need to be handled.
EDIT-Any help?