EntityDataSource.Inserting 事件

定義

發生於新物件保存至資料來源之前。Occurs before a new object is persisted to the data source.

public:
 event EventHandler<System::Web::UI::WebControls::EntityDataSourceChangingEventArgs ^> ^ Inserting;
public event EventHandler<System.Web.UI.WebControls.EntityDataSourceChangingEventArgs> Inserting;
member this.Inserting : EventHandler<System.Web.UI.WebControls.EntityDataSourceChangingEventArgs> 
Public Custom Event Inserting As EventHandler(Of EntityDataSourceChangingEventArgs) 

事件類型

EventHandler<EntityDataSourceChangingEventArgs>

備註

Inserting事件會在將新的物件保存至資料來源之前引發。The Inserting event is raised before a new object is persisted to the data source. Inserting事件可讓您修改或驗證所新增的物件、新增不同的物件,或取消作業。The Inserting event enables you to modify or verify the object being added, add a different object, or cancel the operation. 您可以從物件的屬性存取要加入的物件 Entity EntityDataSourceChangingEventArgsYou can access the object to be added from the Entity property of the EntityDataSourceChangingEventArgs object. 如果提供不同的物件,使用者會負責在屬性中設定正確的實體類型 EntityIf supplying a different object, the user is responsible for setting the correct entity type in the Entity property.

若要停止加入物件,請將物件的 Cancel 屬性設定 EntityDataSourceChangingEventArgstrueTo stop the object from being added, set the Cancel property of the EntityDataSourceChangingEventArgs object to true.

如果在建立新物件時發生錯誤,則 Inserting 會引發事件,並將 Exception 物件的屬性 EntityDataSourceChangingEventArgs 設定為傳回的 ExceptionIf 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.

當您在事件處理常式中處理例外狀況時 Inserting ,請將 ExceptionHandled 屬性設定為 trueWhen you handle the exception in the Inserting event handler, set the ExceptionHandled property to true. 這可避免再次引發例外狀況。This prevents the exception from being raised again. 當您為屬性指定的值時 false ExceptionHandled ,會 EntityDataSource 重新引發例外狀況。When you specify a value of false for the ExceptionHandled property, the EntityDataSource re-raises the exception.

適用於