This documentation is archived and is not being maintained.

LinqDataSourceValidationException Class

Describes an exception that occurred during validation of new or modified values before values are inserted, updated, or deleted by a LinqDataSource control.

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

[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class LinqDataSourceValidationException : Exception, 

The LinqDataSourceValidationException class contains type conversion and property setter exceptions. All of the exceptions that are thrown during validation are contained in the InnerExceptions collection. You can retrieve each validation exception by iterating through the InnerExceptions collection.

You typically handle exceptions in the Updating, Deleting, and Inserting events. If a validation exception is thrown, the Exception property of the LinqDataSourceUpdateEventArgs, LinqDataSourceDeleteEventArgs, or LinqDataSourceInsertEventArgs object contains a LinqDataSourceValidationException object. If no exception is thrown, the Exception property contains null.

To handle validation exceptions, create a handler for the Updating, Deleting, or Inserting event. In the event handler, check whether the Exception property of the event argument class contains a value other than null. If the Exception property is not null, one or more validation exceptions were thrown and you can retrieve each validation exception in the InnerExceptions property.

A validation exception can occur if a value does not match the type of the property. For example, trying to update an integer property by using non-numeric characters causes a validation exception. A LINQ to SQL class can also contain customized validation criteria that make sure that the property contains a value that is within an expected range or pattern.

The following example shows an event handler for the Updating event. It displays any validation exception messages by using a Label control.

Protected Sub LinqDataSource_Updating(ByVal sender As Object, _
        ByVal e As LinqDataSourceUpdateEventArgs)
    If (e.Exception IsNot Nothing) Then
        For Each innerException As KeyValuePair(Of String, Exception) _
               In e.Exception.InnerExceptions
            Label1.Text &= innerException.Key & ": " & _
                innerException.Value.Message & "<br />"
        e.ExceptionHandled = True
    End If
End Sub


protected void LinqDataSource_Updating(object sender, 
        LinqDataSourceUpdateEventArgs e)
    if (e.Exception != null)
        foreach (KeyValuePair<string, Exception> innerException in 
        Label1.Text += innerException.Key + ": " + 
            innerException.Value.Message + "<br />";
        e.ExceptionHandled = true;


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

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5