Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Bronze Contributor
Posts: 125
Registered: ‎12-09-2010

Persistent objects



I noticed that when I work with a smart part and I have an event triggered from a control on the web page, it seems to create a new instance of the class.  I'm trying to initialize an object on form load that then gets used during multiple events, but after the control event fires the object reference seems to be lost.  "object not set to an instance" error.


The issue is I'm calling a webservice that returns a large object filled with all the info I need, and I want to refrain from calling the object again each time I need it.  How can I persist the object during different events?  I only need the object re-initialized again when a new contact is loaded (the data is contact specific).


Basically I start my class with:

public partial class SmartParts_Contact_UsageAndTopups : EntityBoundSmartPartInfoProvider
     private topUpOptionsOutDTO TopupOptions;


I initialize TopupOptions during form load and it works great for the first set of functions called from Form Load.


But then later I trigger an event from a listbox which needs to filter another listbox:


protected void cboVasType_TextChanged(object sender, EventArgs e)
          if(TopupOptions.successful == true)


And at this point when I reference TopupOptions, it fails.