How often do you use Postbacks on asp.net pages? How often do you use it in SharePoint? Well, if you are using postbacks you might know that if you bind your data to a source, e.g. a datatable, the datatable is null after postback. Ok, you can bind your data all the time again meaning you also making request every time against the datasource (database or sharepoint list, etc.).
Well, if you like to store the data which you will bind to a control in a place where it stays? I used the viewstate. I got the hint from this discussion. And used it right this way:
[sourcecode language=”csharp”]
DataTable ds = new DataTable();
//… fill here your Datatable
ViewState.Add(“TicketDaten”, ds);
 
//After Postback reload it
ds = ViewState[“TicketDaten”] as DataTable;
[/sourcecode]
Hope it helps you!
..:: I Like SharePoint ::..
Have you also thought about the Session object?
The ViewState gets serialized and is transmitted with every single page action.
no, but your ideas are always welcome
As Timm already mentioned, the ViewState might not be the best solution. Server-side Caching could be a better approach.
Both ways the datasource is queried only once. The data is transferred too often through the potentially small bandwith Internet connection 🙁