Link to home
Create AccountLog in
Avatar of AdawiAdawi
AdawiAdawiFlag for Jordan

asked on

Store DataTable in view state

Hi All,

I have a datatable object I want to store it in Viewstate but some times an error occurred (not usual

Error: Sys.WebForms.PageRequestManagerServerErrorException: Error serializing value 'Table1' of type 'System.Data.DataTable.'

Any help Please
Avatar of Indrajit Mahajan
Indrajit Mahajan
Flag of India image

Use Session for storing DataTable because Viewstate is not efficient for storing large objects like DataTable as they wrapped with each server request.

  Session[dt] = datatableobj;
Avatar of AdawiAdawi

ASKER

But why I cant use the viewstate, and whey it sometimes working normally and sometimes not ?
DataTable size might increase some times so better to use session..

but if you wanna use viewstate then write code like:

First store datatable values to viewstate ViewState["tempDatatable"] = datatable;

Now to retrieve the same

datatable = (DataTable)(viewstate["tempDAtatable"].ToString())
Dear  indrajitmahajan I know how I can store and retrieve in view viewstate
you can check the issue above :)
It might be based on number of rows stored in datatable that affects the viewstate
ASKER CERTIFIED SOLUTION
Avatar of AdawiAdawi
AdawiAdawi
Flag of Jordan image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
I found the solution for my question :)