Updated: July 2008
The events exposed by the EntityDataSource control enable you to add to ASP.NET applications beyond what is possible in markup-only scenarios. Event handlers can be used to validate data, provide property values for properties that are not data-bound, extract information about query results, and manage the lifecycle of the ObjectContext used to query and update data.
For a description of events in data source controls in general, see Events Associated with Inserting, Updating, and Deleting Capabilities of ASP.NET Data controls.
The ContextCreated event enables you to access the ObjectContext instance that has been created by the EntityDataSource control. This context object can be stored and used for subsequent operations outside the EntityDataSource. For information, see Object Context Life-Cycle Management.
The ContextDisposing event enables you to prevent the ObjectContext used by the EntityDataSource control from being disposed. Handle this event when you want to use a single ObjectContext instance in your page for several controls or instances of the EntityDataSource control.
The Selecting event enables you to modify the configuration of the EntityDataSource and to read or change the arguments from the data-bound control before the query is constructed and executed. Handle this event when you want to modify the paging or sorting behaviors of the control, or to cancel the query.
The Selected event enables you to access the results of a query and retrieve row count information. Handle this event when you want to access object results or store objects in the view state.
The Inserting event enables you to modify or verify the object being added, add a different object, or cancel the operation. Handle this event to access the object to be added from the Entity property of the EntityDataSourceChangingEventArgs object.
The Updating event enables you to modify or verify changes to the object, supply a different object, or cancel the operation before the changes are persisted. You can access the modified object from the Entity property of the EntityDataSourceChangingEventArgs object. Handle this event to verify or validate changes, or to modify the ObjectStateEntry for the object to set different original values for concurrency control. For more information, see Saving Changes and Managing Concurrency (Entity Framework).
The Updated event enables you to access an object that has just had changes persisted to the data source. The Entity property of the EntityDataSourceChangedEventArgs object is used to access the updated object.
The Deleting event enables you to access an object before it is deleted from the data source or to cancel the operation. The Entity property of the EntityDataSourceChangingEventArgs holds the object being deleted.
The Deleted event enables you to access an object that was deleted from the data source. The Entity property of the EntityDataSourceChangingEventArgs object is used to access the deleted object. The returned object is in a Detached state.
The IDynamicDataSource.Exception event is implemented to provide for compatibility with ASP.NET Dynamic Data. A handler for this event cannot be registered in markup. It can be used only when the EntityDataSource instance is cast to an IDynamicDataSource interface. For more information, see ASP.NET Dynamic Data Model Overview.