ObjectDataSourceDisposingEventArgs.ObjectInstance Property

Gets an object that represents the business object with which the ObjectDataSource control performs data operations.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public:
property Object^ ObjectInstance {
	Object^ get ();
}
/** @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.

No code example is currently available or this language may not be supported.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show: