Persist a dataset across postbacks
-
What is the best approach to persist a dataset across postbacks so that users could manipulate the data in it and could be saved(to the database) at last.
-
What is the best approach to persist a dataset across postbacks so that users could manipulate the data in it and could be saved(to the database) at last.
You can put it in
ViewState
.Best wishes, Navaneeth
-
What is the best approach to persist a dataset across postbacks so that users could manipulate the data in it and could be saved(to the database) at last.
You can use viewstate, but if the size of the dataset is very large, it will bloat the request and response size and can probably kill your app. Use a DataTable object and persist it in session. You can also try serializing the object to a database and save the key in viewstate. Each approach has its own advantages and disadvantages. You should try to find out what works best for you.
-
What is the best approach to persist a dataset across postbacks so that users could manipulate the data in it and could be saved(to the database) at last.
The best way is not to Persist the dataset ever. Just save the changes during postbacks and show the most recent data. Remember, the user might go next page on next date. Or might be there is a session timeout. If you store everything in context, that means errors might loose everything. ;)
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Microsoft Bing MAP using Javascript
CLR objects in SQL Server 2005
Uncommon C# Keywords/xml> -
You can use viewstate, but if the size of the dataset is very large, it will bloat the request and response size and can probably kill your app. Use a DataTable object and persist it in session. You can also try serializing the object to a database and save the key in viewstate. Each approach has its own advantages and disadvantages. You should try to find out what works best for you.
Hello Shameel How about persisting the DataSet(as I have more than one DataTable) in a Session variable and clearing it(using Session.Remove()) while the user navigates away from the page?
-
You can put it in
ViewState
.Best wishes, Navaneeth
I am using ViewState now but I notice the page is slower during reloads
-
The best way is not to Persist the dataset ever. Just save the changes during postbacks and show the most recent data. Remember, the user might go next page on next date. Or might be there is a session timeout. If you store everything in context, that means errors might loose everything. ;)
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Microsoft Bing MAP using Javascript
CLR objects in SQL Server 2005
Uncommon C# Keywords/xml>Thank you Abhishek You re right. But here I am faced with a situation to reduce database hits rather than concurrency. I am having multiple tables so using DataSet. When I stored it in a ViewState variable I notice the page loading slower.
-
Thank you Abhishek You re right. But here I am faced with a situation to reduce database hits rather than concurrency. I am having multiple tables so using DataSet. When I stored it in a ViewState variable I notice the page loading slower.
Dont load such a huge data in ViewState. When you request for something, you send viewstate with it(even if it is an AJAX request). After receiving the viewstate it decrypts it using Machine key. It then modifies the viewstate according to your serverside program and then finally encrypts it... converts the encrypted string to Base64 and written over Response stream. That means for every request this huge amount of task IIS has to perform. Hence slow output. We generally place
EnableViewState = false
for frequently visited pages to have better performance. So according to me writing a Dataset(which serializes it and write to page) is not good. On the other hand, Server memory is very low. If there are lots of connections, there might be a huge possibility to have Session OutofMemory. But if you dont have concurrent connections, you might use Session. But dont put the dataset, as there are a lots of properties which are not required. Rather make a list of DataRows and place them in session(Improves than writing DataSet). But still, I dont like this as well. If I was there, I will always compromise Database hits than Server memory. :thumbsup:Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using Javascript