In my application i have few datatables. but one of the datatable is getting cleared when the page postbacks. Sometimes it works fine. sometimes i am facing this issue. Can anybody help me out pls.
Code Snippet:
public static DataTable dtAnswer = new DataTable();
public static DataTable dtPartitioned = new DataTable();
public static DataTable dtAnsCount;
getting an error at this point,
if (dtAnsCount.Columns.Count == 0)
{
}
Note:[The error is occuring at certain instance - saying object reference not set to an instance, which says that datatable doesn't exists]
Thanks in Advance!
Regards,
Divya
Jignesh TrivediPosted May 9, 2013, 8:26 AM
hi,
as per my knowledge ASP.net is stateless, so it does not maintain any state between server and client.
you may put your data table in Session so that when ever you come back you may find it.
Assignment
Session["myData"] = datatable;
Retrieving...
DataTable dt = Session["myData"] as DataTable;
hope this will help you.
Divya JagadeeshPosted May 10, 2013, 1:18 AM
Regards,
Divya
Divya JagadeeshPosted May 9, 2013, 3:01 AM
I have tested using this way too - public static DataTable dtAnsCount=new DataTable();
still i am getting the same issue. The Datatable itself getting vanishing.
For other datatables i got issue like, columns are getting cleared that's the reason i was checking this condition
dt.columns.rows...
Regards,
Divya
Ravi ShekharPosted May 9, 2013, 2:43 AM
Where you create a new object of your dtAnsCount datatable?
without using this,
public static DataTable dtAnsCount=new DataTable();
how you use dtAnsCount.Columns.Count
i think you should use public static DataTable dtAnsCount=new DataTable();
Regards,
ravi
Please mark it as answer if it helped.