LinqDataSourceDeleteEventArgs Class (System.Web.UI.WebControls)

Switch View :
ScriptFree
.NET Framework Class Library
LinqDataSourceDeleteEventArgs Class

Provides data for the Deleting event.

Inheritance Hierarchy

System.Object
  System.EventArgs
    System.ComponentModel.CancelEventArgs
      System.Web.UI.WebControls.LinqDataSourceDeleteEventArgs

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

Visual Basic
Public Class LinqDataSourceDeleteEventArgs _
	Inherits CancelEventArgs
C#
public class LinqDataSourceDeleteEventArgs : CancelEventArgs
Visual C++
public ref class LinqDataSourceDeleteEventArgs : public CancelEventArgs
F#
type LinqDataSourceDeleteEventArgs =  
    class
        inherit CancelEventArgs
    end

The LinqDataSourceDeleteEventArgs type exposes the following members.

Constructors

  Name Description
Public method LinqDataSourceDeleteEventArgs(LinqDataSourceValidationException) Initializes a new instance of the LinqDataSourceDeleteEventArgs class with the specified exception.
Public method LinqDataSourceDeleteEventArgs(Object) Initializes a new instance of the LinqDataSourceDeleteEventArgs class.
Top
Properties

  Name Description
Public property Cancel Gets or sets a value indicating whether the event should be canceled. (Inherited from CancelEventArgs.)
Public property Exception Gets the exception that was thrown while the data was being validated before the delete operation.
Public property ExceptionHandled Gets or sets a value that indicates whether the exception was handled and that it should not be thrown again.
Public property OriginalObject Gets the object that represents the data to delete.
Top
Methods

  Name Description
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top
Remarks

The LinqDataSourceDeleteEventArgs object is passed to any handler for the Deleting event. The OriginalObject property contains the data that will be deleted.

If the object that represents the data source throws a validation exception before it deletes the data, the Exception property contains an instance of the LinqDataSourceValidationException class. You can retrieve all the validation exceptions through the InnerExceptions property. If no validation exception is thrown, the Exception property contains null. If you handle the validation exceptions and do not want the exception to be re-thrown, set the ExceptionHandled property to true.

You create an event handler for the Deleting event to validate the data, to examine validation errors from the data class, or to cancel the delete operation. You cancel the delete operation by setting the Cancel property to true.

By default, the LinqDataSource control stores the original values from the data source in view state in the Web page, except those whose ColumnAttribute attribute is marked as UpdateCheck.Never. LINQ to SQL automatically checks the integrity of the data before deleting the data. It does this by comparing the current values in the data source with the original values that are stored in view state. You can perform additional data validation by creating a handler for the Deleting event.

Examples

The following example shows how to cancel the delete operation based on a property in the OriginalObject property and a value from the Web page. In the example, users must select a CheckBox control to confirm that they want to delete a product record when its OnSale property is set to true.

Visual Basic

Protected Sub LinqDataSource_Deleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceDeleteEventArgs)
    Dim product As Product
    product = CType(e.OriginalObject, Product)

    If (product.OnSale And Not confirmCheckBox.Checked) Then
        e.Cancel = True
    End If
End Sub


C#

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


Version Information

.NET Framework

Supported in: 4, 3.5
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also

Reference

Other Resources