Q

Mysterious error when updating a DataTable-based datagrid

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.

This was first published in July 2004

Dig deeper on Win Development Resources

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchCloudComputing

SearchSoftwareQuality

SearchSOA

TheServerSide

SearchCloudApplications

Close