Is there any other way to store the data source other than view state?

℡╲_俬逩灬. 提交于 2020-01-02 09:58:41

问题


I have a page on which data table is created programmatically if the data is not there in the database tables. I have to use this data table in many events during postbacks. The data table may contain hundreds of records and there may be multiple users accessing the same page(Of course with different data source for each user). I am storing the data table in view state but I am afraid that this practice will make the page heavier. Is there any other way to preserve the data table across postbacks.The code is very long so I can not copy and past it here.

Using session will again make the whole application heavier...So is it better choice over viewstate??


回答1:


In your case the view state can get very big and will hurt page load performance. IMHO the best thing would be to revise the way your are handling the post back events.

  • Use Caching if more than one user needs the same data.
  • Using the Session if the data is specific for each zuser. But keep in mind, that if you are in a clustered invironment it has some pitfalls.
  • Load the data from the database each time the user posts back to the server. No Statehandling on the server needs to be done but you loose performance while doing a network roundtrip.

For a quick fix I usually store the View State on the server. Refer to this page to read about it... http://aspguy.wordpress.com/2008/07/09/reducing-the-page-size-by-storing-viewstate-on-server/




回答2:


You should use Session. Also it's possible to use Application or Cache but you'll have to generate and store a unique key on your page to negate possible interferention between requests from different users.




回答3:


May be you need to store the data in the Cache object




回答4:


If the data table is different for each user, you should use Session or you could use Cache , assumed to make a different Cache object for each user.

But if the data table is very big probably is not a good idea to store it in memory instead of direct db access.




回答5:


If data is user specific then you can use Session. However, in case of out of process session state, you may have issues because all that data needs to be marshaled back & forth from session store.

Otherwise Cache is a good option but you need to choose cache period and expiration policy on typical usage scenarios (and also need to handle cache expiry scenario gracefully).

Yet another option is to push the data into temp file - however, in such case, you need to manage file clean up etc.



来源:https://stackoverflow.com/questions/7468048/is-there-any-other-way-to-store-the-data-source-other-than-view-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!