I am getting an error when trying to do an Update to a datagrid based on a DataTable: "Object reference not set
to an instance of an object" Any help or suggestions are greatly appreciated! Your problem is with Session State. When your application sends a web page to the browser the server destroys your application variables. So your dtglobal and dvglobal objects will no longer be instantiated on a subsequent postback.
One way to overcome this problem is to save these objects in session state and retrieve them in Page_Load.
You can add the following lines of code to the end of your "btCreateObjs_Click" method to save the objects in session state:
Me.Session.Add("dtGlobal", dtglobal) Me.Session.Add("dvGlobal", dtglobal)
And, you can add the following lines of code to the Page_Load method to retrieve the objects from session state:
dtglobal = DirectCast(Me.Session("dtGlobal"), DataTable) dvglobal = DirectCast(Me.Session("dvGlobal"), DataView
You need to remember that when the web page is on the client, you are no longer on the server. The only objects retained on the server are those in session state or cache.
Dig deeper on Win Development Resources
Related Q&A from Samuel Matzen
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.