Reputation: 2371
As by the Question .Is this a Good Practice to store a datable in view state If not then what i need to do for Performance and security measures.
What i lacks when i go with security and to performance and viceversa.
What i trying to do. is showing data in Gridview by DataTable(Source ) .In the postBacks. i want to save my Query Cost.Load data from view state or Cache object but not by Database.
Upvotes: 2
Views: 1575
Reputation: 499132
A DataTable
is quite a large object - storing it in ViewState
will bloat it and add to the download times of each request it is present on. In this respect not good for performance.
In terms of security - ViewState
can be deciphered on the client side, so the DataTable
is not secure.
What you need to do depends on what you are trying to achieve (which you have not indicated at all in your question).
You may want to store it server side in the Cache
or Session
objects, re-fetch it from the data store. It depends on the requirements.
Upvotes: 1
Reputation: 8008
No it is not good practices to do it, storing a datatable in the viewstate will make your page grow big in size, thus slow both for the users and for your server to process.
If you need to keep the datatable around, you can add it to a Cache or just requery it every time
Upvotes: 2
Reputation: 1414
Usually, the viewstate should be kept small. Can't you store your datatable in a cache or in session(not so good). Saying that it won't be secure depend if your viewstate is encrypted or not.
Upvotes: 1