.NET Framework Class Library LinqDataSourceUpdateEventArgs Class

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

Syntax
Public Class LinqDataSourceUpdateEventArgs _
Inherits CancelEventArgs
public class LinqDataSourceUpdateEventArgs : CancelEventArgs
public ref class LinqDataSourceUpdateEventArgs : public CancelEventArgs
type LinqDataSourceUpdateEventArgs =
class
inherit CancelEventArgs
end
The LinqDataSourceUpdateEventArgs type exposes the following members.

Constructors

Methods

Remarks
The LinqDataSourceUpdateEventArgs object is passed to any event handler for the Updating event. You can use the LinqDataSourceUpdateEventArgs object to examine the data before the update operation is executed in the data source. You can then validate the data, examine validation exceptions thrown by the data class, or change a value before the update. You can also cancel the update operation. The OriginalObject object contains the data that was originally retrieved from the data source. The NewObject object contains the data that will be saved in the data source during the update operation. If the object that represents the data source throws a validation exception before updating 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 nullNothingnullptra null reference (Nothing in Visual Basic). If you handle the validation exceptions and do not want the exception to be re-thrown, set the ExceptionHandled property to true. By default, the LinqDataSource control stores the original values from the data source in view state on the Web page, except those whose ColumnAttribute attribute is marked as UpdateCheck.Never. LINQ to SQL automatically checks the integrity of the data before updating the data. It does this by comparing the current values in the data source with the original values stored in view state. LINQ to SQL raises an exception if the values in the data source have changed. You can perform additional data validation by creating a handler for the Updating event.

Examples
The following example shows an event handler for the Updating event. The example shows how to compare properties from the OriginalObject property and the NewObject property to determine whether the value in the Category property has changed. If so, the CategoryChanged property of the object in the NewObject property is set to true.
Protected Sub LinqDataSource_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceUpdateEventArgs)
Dim originalProduct As Product
Dim newProduct As Product
originalProduct = CType(e.OriginalObject, Product)
newProduct = CType(e.NewObject, Product)
If (originalProduct.Category <> newProduct.Category) Then
newProduct.CategoryChanged = True
End If
End Sub
protected void LinqDataSource_Updating(object sender, LinqDataSourceUpdateEventArgs e)
{
Product originalProduct = (Product)e.OriginalObject;
Product newProduct = (Product)e.NewObject;
if (originalProduct.Category != newProduct.Category)
{
newProduct.CategoryChanged = true;
}
}
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 LinqDataSourceUpdateEventArgs, classe Fournit des données pour l'événement Updating.

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

Syntaxe
Public Class LinqDataSourceUpdateEventArgs _
Inherits CancelEventArgs
public class LinqDataSourceUpdateEventArgs : CancelEventArgs
public ref class LinqDataSourceUpdateEventArgs : public CancelEventArgs
type LinqDataSourceUpdateEventArgs =
class
inherit CancelEventArgs
end
Le type LinqDataSourceUpdateEventArgs expose les membres suivants.

Constructeurs

Méthodes

Notes
L'objet LinqDataSourceUpdateEventArgs est passé à un gestionnaire d'événements pour l'événement Updating. Vous pouvez utiliser l'objet LinqDataSourceUpdateEventArgs pour examiner les données avant d'exécuter l'opération de mise à jour dans la source de données. Vous pouvez alors valider les données, examiner les exceptions de validation levées par la classe de données ou modifier une valeur avant la mise à jour. Vous pouvez également annuler l'opération de mise à jour. L'objet OriginalObject contient les données récupérées à l'origine de la source de données. L'objet NewObject contient les données qui seront enregistrées dans la source de données lors de l'opération de mise à jour. Si l'objet qui représente la source de données lève une exception de validation avant la mise à jour des données, la propriété Exception contient une instance de la classe LinqDataSourceValidationException. Vous pouvez alors récupérer toutes les exceptions de validation par l'intermédiaire de la propriété InnerExceptions. Si aucune exception de validation n'est levée, la propriété Exception contient nullNothingnullptrune référence null (Nothing en Visual Basic). Si vous gérez les exceptions de validation et souhaitez qu'elles ne soient plus levées, affectez la valeur true à la propriété ExceptionHandled. Par défaut, le contrôle LinqDataSource stocke les valeurs d'origine de la source de données sur la page Web dans l'état d'affichage, sauf celles dont l'attribut ColumnAttribute est marqué comme UpdateCheck.Never. La requête LINQ to SQL vérifie automatiquement l'intégrité des données avant de les mettre à jour. Pour cela, elle compare les valeurs en cours de la source de données avec les valeurs d'origine stockées dans l'état d'affichage. LINQ to SQL lève une exception si les valeurs de la source de données ont été modifiées. Vous pouvez exécuter une validation supplémentaire des données en créant un gestionnaire pour l'événement Updating.

Exemples
L'exemple suivant montre un gestionnaire d'événements pour l'événement Updating. L'exemple indique comment comparer les propriétés de la propriété OriginalObject et de la propriété NewObject pour déterminer si la valeur de la propriété Category a été modifiée. Si c'est le cas, la propriété CategoryChanged de l'objet dans la propriété NewObject a la valeur true.
Protected Sub LinqDataSource_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceUpdateEventArgs)
Dim originalProduct As Product
Dim newProduct As Product
originalProduct = CType(e.OriginalObject, Product)
newProduct = CType(e.NewObject, Product)
If (originalProduct.Category <> newProduct.Category) Then
newProduct.CategoryChanged = True
End If
End Sub
protected void LinqDataSource_Updating(object sender, LinqDataSourceUpdateEventArgs e)
{
Product originalProduct = (Product)e.OriginalObject;
Product newProduct = (Product)e.NewObject;
if (originalProduct.Category != newProduct.Category)
{
newProduct.CategoryChanged = true;
}
}
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
RéférenceAutres ressources
|