ObjectDataSourceDisposingEventArgs.ObjectInstance Property
Assembly: System.Web (in system.web.dll)
/** @property */ public Object get_ObjectInstance ()
public function get ObjectInstance () : Object
Not applicable.
Property Value
The business object the ObjectDataSource uses to data operations; otherwise, a null reference (Nothing in Visual Basic), if a null reference (Nothing in Visual Basic) is passed to the ObjectDataSourceEventArgs.If the data operation methods (SelectMethod, UpdateMethod, DeleteMethod, and InsertMethod) are instance methods, an instance of the business object is created before the method is executed. You can prevent the business object from being created for each call by saving the object in the ObjectInstance property in the ObjectDisposing event handler. In subsequent ObjectCreating events, you can retrieve the business object from the ObjectInstance property.
The following code example demonstrates how to use an ObjectDataSource control with a business object and a GridView control to display information. You might work with a business object that is very expensive (in terms of time or resources) to create for every data operation that your Web page performs. One way to work with an expensive object might be to create an instance of it once, and then cache it for subsequent operations instead of creating and destroying it for every data operation. This example demonstrates this pattern. You can handle the ObjectCreating event to check the cache for an object first, and then create an instance, only if one is not already cached. Then, handle the ObjectDisposing event to cache the business object for future use, instead of destroying it. In this example, the CancelEventArgs.Cancel property of the ObjectDataSourceDisposingEventArgs class is set to true, to direct the ObjectDataSource to not call Dispose on the instance.