.NET Framework Class Library 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.

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

Syntax
<SerializableAttribute> _
Public Class LinqDataSourceValidationException _
Inherits Exception _
Implements IDynamicValidatorException, ISerializable
[SerializableAttribute]
public class LinqDataSourceValidationException : Exception,
IDynamicValidatorException, ISerializable
[SerializableAttribute]
public ref class LinqDataSourceValidationException : public Exception,
IDynamicValidatorException, ISerializable
[<SerializableAttribute>]
type LinqDataSourceValidationException =
class
inherit Exception
interface IDynamicValidatorException
interface ISerializable
end
The LinqDataSourceValidationException type exposes the following members.

Constructors

Methods

Events
|
| Name | Description |
|---|
.gif) | SerializeObjectState | Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception. (Inherited from Exception.) | Top

Remarks
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 nullNothingnullptra null reference (Nothing in Visual Basic). 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 nullNothingnullptra null reference (Nothing in Visual Basic). 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.

Examples
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 />"
Next
e.ExceptionHandled = True
End If
End Sub
[C#]
protected void LinqDataSource_Updating(object sender,
LinqDataSourceUpdateEventArgs e)
{
if (e.Exception != null)
{
foreach (KeyValuePair<string, Exception> innerException in
e.Exception.InnerExceptions)
{
Label1.Text += innerException.Key + ": " +
innerException.Value.Message + "<br />";
}
e.ExceptionHandled = true;
}
}

Version Information
.NET FrameworkSupported in: 4, 3.5

Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), 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
|
Bibliothèque de classes .NET Framework LinqDataSourceValidationException, classe Décrit une exception qui s'est produite durant la validation de valeurs nouvelles ou modifiées avant que des valeurs ne soient insérées, mises à jour ou supprimées par un contrôle LinqDataSource.

Hiérarchie d'héritage
Espace de noms :
System.Web.UI.WebControls
Assembly :
System.Web.Extensions (dans System.Web.Extensions.dll)

Syntaxe
<SerializableAttribute> _
Public Class LinqDataSourceValidationException _
Inherits Exception _
Implements IDynamicValidatorException, ISerializable
[SerializableAttribute]
public class LinqDataSourceValidationException : Exception,
IDynamicValidatorException, ISerializable
[SerializableAttribute]
public ref class LinqDataSourceValidationException : public Exception,
IDynamicValidatorException, ISerializable
[<SerializableAttribute>]
type LinqDataSourceValidationException =
class
inherit Exception
interface IDynamicValidatorException
interface ISerializable
end
Le type LinqDataSourceValidationException expose les membres suivants.

Constructeurs

Méthodes

Événements
|
| Nom | Description |
|---|
.gif) | SerializeObjectState | Se produit lorsqu'une exception est sérialisée pour créer un objet d'état d'exception qui contient des données sérialisées relatives à l'exception. (Hérité de Exception.) | Début

Notes
La classe LinqDataSourceValidationException contient la conversion de type et des exceptions d'accesseur Set de propriété. Toutes les exceptions levées pendant la validation sont contenues dans la collection InnerExceptions. Vous pouvez extraire chaque exception de validation en itérant au sein de la collection InnerExceptions. Vous gérez en général des exceptions dans l' Updating, Deleting et les événements Inserting. Si une exception de validation est levée, la propriété Exception du LinqDataSourceUpdateEventArgs, LinqDataSourceDeleteEventArgs, ou l'objet LinqDataSourceInsertEventArgs contient un objet LinqDataSourceValidationException. Si aucune exception n'est levée, la propriété Exception contient nullNothingnullptrune référence null (Nothing en Visual Basic). Pour gérer des exceptions de validation, créez un gestionnaire pour Updating, Deleting ou l'événement Inserting. Dans le gestionnaire d'événements, vérifiez si la propriété Exception de la classe d'arguments d'événements contient une valeur autre que nullNothingnullptrune référence null (Nothing en Visual Basic). Si la propriété Exception n'est pas nulle, une ou plusieurs exceptions de validation ont été levées et vous pouvez extraire chacune d'entre elles dans la propriété InnerExceptions. Une exception de validation peut se produire si une valeur ne correspond pas au type de la propriété. Par exemple, la tentative de mise à jour d'une propriété d'entier à l'aide de caractères non numériques provoque une exception de validation. Une classe LINQ to SQL peut également contenir des critères de validation personnalisés qui s'assurent que la propriété contient une valeur figurant dans une plage ou un modèle prévu.

Exemples
L'exemple suivant montre un gestionnaire d'événements pour l'événement Updating. Il affiche tous les messages d'exception de validation à l'aide d'un contrôle Label.
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 />"
Next
e.ExceptionHandled = True
End If
End Sub
[C#]
protected void LinqDataSource_Updating(object sender,
LinqDataSourceUpdateEventArgs e)
{
if (e.Exception != null)
{
foreach (KeyValuePair<string, Exception> innerException in
e.Exception.InnerExceptions)
{
Label1.Text += innerException.Key + ": " +
innerException.Value.Message + "<br />";
}
e.ExceptionHandled = true;
}
}

Informations de version
.NET FrameworkPris en charge dans : 4, 3.5

Plateformes
Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

Sécurité des threads
Tous les membres static ( Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Voir aussi
|