Share via


EntityDataSource Events

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.

Event

Description

ContextCreating

The ContextCreating event provides an ObjectContext instance to be used by the EntityDataSource control for subsequent operations. For information, see Object Context Life-Cycle Management.

ContextCreated

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.

ContextDisposing

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.

Selecting

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.

Selected

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.

Inserting

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.

Inserted

The Inserted event enables you to access an object created in the data source. The Entity property of the EntityDataSourceChangedEventArgs object is used to access the added object.

Updating

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).

Updated

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.

Deleting

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.

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.

Exception()

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.

See Also

Concepts

Object Context Life-Cycle Management (EntityDataSource)

Configuring the EntityDataSource Control

Updating Data (EntityDataSource)

EntityDataSource Designer

Other Resources

Data Selection using EntityDataSource

Using ASP.NET Dynamic Data

Change History

Date

History

Reason

July 2008

Added topic.

SP1 feature change.