Export (0) Print
Expand All

LinqDataSource.Deleting Event

Occurs before a delete operation.

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

public event EventHandler<LinqDataSourceDeleteEventArgs> Deleting
<asp:LinqDataSource OnDeleting="EventHandler" />

Handle the Deleting event to validate the object to be deleted, to examine data validation errors from the data class, to change a value before the delete operation, or to cancel the delete operation. The LinqDataSource control passes a LinqDataSourceDeleteEventArgs object to event handlers for the Deleting event. The LinqDataSourceDeleteEventArgs object contains the data that will be deleted and enables you to cancel the delete operation. If the data class throws a LinqDataSourceValidationException exception, the LinqDataSourceDeleteEventArgs object contains that exception in the Exception property.

If an exception is thrown in an event handler for the Deleting event, you must handle the exception in that event handler. The exception will not be passed to an event handler for the Deleted event (through the Exception property of the LinqDataSourceStatusEventArgs object). The Exception property contains only the exceptions that are thrown after the Deleting event.

The following example shows an event handler for the Deleting event. The code cancels the delete operation based on a property in the OriginalObject property and a value from the Web page. In the example, when the OnSale property is set to true, the user must select a CheckBox control to confirm that a record should be deleted.

protected void LinqDataSource_Deleting(object sender, LinqDataSourceDeleteEventArgs e)
{
    Product product = (Product)e.OriginalObject;
    if (product.OnSale && !confirmCheckBox.Checked)
    {
        e.Cancel = true;
    }
}

.NET Framework

Supported in: 4.5, 4, 3.5

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft