ASP.NET datasets and memory
I am using framework 2.0, and I don't understand how the datagrid and the datasets works after doing a postback. In msdn says that there's no need to do a databind again if the request 开发者_JAVA百科is a postback. But my question is: how the datagrid shows again the records if there is no databind? I supose that asp.net saves in a cache the query results, but I am not sure. Please tell me what is the mechanism that .NET uses to accomplish it.
I have a large query result (hundreds), paginated each 50 records, and I want to avoid doing the same query every time the user select the next 50 records.
Thanks in advance.
The answer to this is the viewstate. The whole displayed grid is stored in the viewstate and it is this that persists across postbacks.
That is the grid is defined on the initial page load and stored in the viewstate. When the user clicks a link/button to postback the form the viewstate is then decoded and is available for use again. Therefore you don't need to rebind the grid. However said there are some caveats to be aware of.
ASP.NET saves your previous values into ViewState, so they aren't get lost between postbacks.
But in your case you're talking about pagination, the new records. If you're retrieving them at first request, maybe you can store them at viewstate but it's not a good idea. Your page will be served very slow if you have much records.
If your clients getting the same data every time, and the current data changes are not important while showing data, maybe you can cache it with asp.net's caching mechanism.
Viewstate is the magic word :P
ASP.NET WebForms is all about ViewState.
The concept is basically that ASP.NET is storing the information in a hidden input element on your page and then automatically retrieving it server side using postbacks, which posts the form (wrapped around your whole site) back to the server.
精彩评论