Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

EntityDataSource::Inserting Event

 

Occurs before a new object is persisted to the data source.

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

public:
event EventHandler<EntityDataSourceChangingEventArgs^>^ Inserting {
	void add(EventHandler<EntityDataSourceChangingEventArgs^>^ value);
	void remove(EventHandler<EntityDataSourceChangingEventArgs^>^ value);
}

The Inserting event is raised before a new object is persisted to the data source. The Inserting event enables you to modify or verify the object being added, add a different object, or cancel the operation. You can access the object to be added from the Entity property of the EntityDataSourceChangingEventArgs object. If supplying a different object, the user is responsible for setting the correct entity type in the Entity property.

To stop the object from being added, set the Cancel property of the EntityDataSourceChangingEventArgs object to true.

If an error occurs when creating a new object, the Inserting event is raised and the Exception property of the EntityDataSourceChangingEventArgs object is set to the returned Exception.

When you handle the exception in the Inserting event handler, set the ExceptionHandled property to true. This prevents the exception from being raised again. When you specify a value of false for the ExceptionHandled property, the EntityDataSource re-raises the exception.

.NET Framework
Available since 3.5
Return to top
Show:
© 2017 Microsoft