/
LinqDataSourceInsertEventArgs.xml
332 lines (300 loc) · 20.4 KB
/
LinqDataSourceInsertEventArgs.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<Type Name="LinqDataSourceInsertEventArgs" FullName="System.Web.UI.WebControls.LinqDataSourceInsertEventArgs">
<TypeSignature Language="C#" Value="public class LinqDataSourceInsertEventArgs : System.ComponentModel.CancelEventArgs" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi beforefieldinit LinqDataSourceInsertEventArgs extends System.ComponentModel.CancelEventArgs" />
<TypeSignature Language="DocId" Value="T:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs" />
<TypeSignature Language="VB.NET" Value="Public Class LinqDataSourceInsertEventArgs
Inherits CancelEventArgs" />
<TypeSignature Language="F#" Value="type LinqDataSourceInsertEventArgs = class
 inherit CancelEventArgs" />
<TypeSignature Language="C++ CLI" Value="public ref class LinqDataSourceInsertEventArgs : System::ComponentModel::CancelEventArgs" />
<AssemblyInfo>
<AssemblyName>System.Web.Extensions</AssemblyName>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.ComponentModel.CancelEventArgs</BaseTypeName>
</Base>
<Interfaces />
<Docs>
<summary>Provides data for the <see cref="E:System.Web.UI.WebControls.LinqDataSource.Inserting" /> event.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs> object is passed to any event handler for the <xref:System.Web.UI.WebControls.LinqDataSource.Inserting> event. The <xref:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs.NewObject%2A> property contains the data that will be inserted.
You can use the <xref:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs> object to examine the data before the insert operation is executed in the data source. You can then validate the data, examine validation errors from the data class, or change a value before the update. You can also cancel the insert operation.
If the object that represents the data source throws a validation exception before it inserts the data, the <xref:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs.Exception%2A> property contains an instance of the <xref:System.Web.UI.WebControls.LinqDataSourceValidationException> class. You can retrieve all the validation exceptions through the <xref:System.Web.UI.WebControls.LinqDataSourceValidationException.InnerExceptions%2A> property. If no validation exception is thrown, the <xref:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs.Exception%2A> property contains `null`. If you handle the validation exceptions and do not want the exception to be re-thrown, set the <xref:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs.ExceptionHandled%2A> property to `true`.
## Examples
The following example shows a handler for the <xref:System.Web.UI.WebControls.LinqDataSource.Inserting> event. The object from the <xref:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs.NewObject%2A> property is cast to a type named `Product`. The `DateModified` property of the `Product` object is set to the current date and time.
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_WebNet/System.Web.UI.WebControls.LinqDataSource.Inserting/cs/Default.aspx.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/System.Web.UI.WebControls.LinqDataSource.Inserting/vb/Default.aspx.vb" id="Snippet1":::
The following example shows an event handler for the <xref:System.Web.UI.WebControls.LinqDataSource.Inserting> event. It displays any validation exception messages by using a <xref:System.Web.UI.WebControls.Label> control.
```vb
Protected Sub LinqDataSource_Inserting(ByVal sender As Object, _
ByVal e As LinqDataSourceInsertEventArgs)
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
```
```csharp
protected void LinqDataSource_Inserting(object sender,
LinqDataSourceInsertEventArgs 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;
}
}
```
]]></format>
</remarks>
</Docs>
<Members>
<MemberGroup MemberName=".ctor">
<AssemblyInfo>
<AssemblyName>System.Web.Extensions</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Initializes a new instance of the <see cref="T:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs" /> class.</summary>
</Docs>
</MemberGroup>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public LinqDataSourceInsertEventArgs (object newObject);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(object newObject) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs.#ctor(System.Object)" />
<MemberSignature Language="VB.NET" Value="Public Sub New (newObject As Object)" />
<MemberSignature Language="F#" Value="new System.Web.UI.WebControls.LinqDataSourceInsertEventArgs : obj -> System.Web.UI.WebControls.LinqDataSourceInsertEventArgs" Usage="new System.Web.UI.WebControls.LinqDataSourceInsertEventArgs newObject" />
<MemberSignature Language="C++ CLI" Value="public:
 LinqDataSourceInsertEventArgs(System::Object ^ newObject);" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web.Extensions</AssemblyName>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<Parameters>
<Parameter Name="newObject" Type="System.Object" />
</Parameters>
<Docs>
<param name="newObject">An object that contains the data to insert.</param>
<summary>Initializes a new instance of the <see cref="T:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs" /> class.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public LinqDataSourceInsertEventArgs (System.Web.UI.WebControls.LinqDataSourceValidationException exception);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(class System.Web.UI.WebControls.LinqDataSourceValidationException exception) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs.#ctor(System.Web.UI.WebControls.LinqDataSourceValidationException)" />
<MemberSignature Language="VB.NET" Value="Public Sub New (exception As LinqDataSourceValidationException)" />
<MemberSignature Language="F#" Value="new System.Web.UI.WebControls.LinqDataSourceInsertEventArgs : System.Web.UI.WebControls.LinqDataSourceValidationException -> System.Web.UI.WebControls.LinqDataSourceInsertEventArgs" Usage="new System.Web.UI.WebControls.LinqDataSourceInsertEventArgs exception" />
<MemberSignature Language="C++ CLI" Value="public:
 LinqDataSourceInsertEventArgs(System::Web::UI::WebControls::LinqDataSourceValidationException ^ exception);" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web.Extensions</AssemblyName>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<Parameters>
<Parameter Name="exception" Type="System.Web.UI.WebControls.LinqDataSourceValidationException" />
</Parameters>
<Docs>
<param name="exception">The exception that occurred when the data to insert was being validated.</param>
<summary>Initializes a new instance of the <see cref="T:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs" /> class and specifies the provided exception.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="Exception">
<MemberSignature Language="C#" Value="public System.Web.UI.WebControls.LinqDataSourceValidationException Exception { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance class System.Web.UI.WebControls.LinqDataSourceValidationException Exception" />
<MemberSignature Language="DocId" Value="P:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs.Exception" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property Exception As LinqDataSourceValidationException" />
<MemberSignature Language="F#" Value="member this.Exception : System.Web.UI.WebControls.LinqDataSourceValidationException" Usage="System.Web.UI.WebControls.LinqDataSourceInsertEventArgs.Exception" />
<MemberSignature Language="C++ CLI" Value="public:
 property System::Web::UI::WebControls::LinqDataSourceValidationException ^ Exception { System::Web::UI::WebControls::LinqDataSourceValidationException ^ get(); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web.Extensions</AssemblyName>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Web.UI.WebControls.LinqDataSourceValidationException</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets the exception that was thrown while the data was being validated before the insert operation.</summary>
<value>The exception, if an error occurred; otherwise, <see langword="null" />.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
If a validation exception is thrown before the insert operation is performed, the exception is stored in the <xref:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs.Exception%2A> property. In a handler for the <xref:System.Web.UI.WebControls.LinqDataSource.Inserting> event, you can retrieve the exception through the <xref:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs.Exception%2A> property.
## Examples
The following example shows a handler for the <xref:System.Web.UI.WebControls.LinqDataSource.Inserting> event. It displays any validation exception messages by using a <xref:System.Web.UI.WebControls.Label> control.
```vb
Protected Sub LinqDataSource_Inserting(ByVal sender As Object, _
ByVal e As LinqDataSourceInsertEventArgs)
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
```
```csharp
protected void LinqDataSource_Inserting(object sender,
LinqDataSourceInsertEventArgs 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;
}
}
```
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="ExceptionHandled">
<MemberSignature Language="C#" Value="public bool ExceptionHandled { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance bool ExceptionHandled" />
<MemberSignature Language="DocId" Value="P:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs.ExceptionHandled" />
<MemberSignature Language="VB.NET" Value="Public Property ExceptionHandled As Boolean" />
<MemberSignature Language="F#" Value="member this.ExceptionHandled : bool with get, set" Usage="System.Web.UI.WebControls.LinqDataSourceInsertEventArgs.ExceptionHandled" />
<MemberSignature Language="C++ CLI" Value="public:
 property bool ExceptionHandled { bool get(); void set(bool value); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web.Extensions</AssemblyName>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[set: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<set: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets a value that indicates whether the exception was handled and that it should not be thrown again.</summary>
<value>
<see langword="true" /> if the exception was handled; otherwise, <see langword="false" />.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
You can create event handlers for the <xref:System.Web.UI.WebControls.LinqDataSource.Inserting> event to examine validation exceptions that occurred before the insert operation. If you handle the exception and do not want it to be thrown again, set the <xref:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs.ExceptionHandled%2A> property to `true`. If you do not set the <xref:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs.ExceptionHandled%2A> property to `true`, the exception will be propagated to the next event handler in the call stack.
## Examples
The following example shows an event handler for the <xref:System.Web.UI.WebControls.LinqDataSource.Inserting> event. It displays any validation exception messages by using a <xref:System.Web.UI.WebControls.Label> control.
```vb
Protected Sub LinqDataSource_Inserting(ByVal sender As Object, _
ByVal e As LinqDataSourceInsertEventArgs)
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
```
```csharp
protected void LinqDataSource_Inserting(object sender,
LinqDataSourceInsertEventArgs 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;
}
}
```
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="NewObject">
<MemberSignature Language="C#" Value="public object NewObject { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance object NewObject" />
<MemberSignature Language="DocId" Value="P:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs.NewObject" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property NewObject As Object" />
<MemberSignature Language="F#" Value="member this.NewObject : obj" Usage="System.Web.UI.WebControls.LinqDataSourceInsertEventArgs.NewObject" />
<MemberSignature Language="C++ CLI" Value="public:
 property System::Object ^ NewObject { System::Object ^ get(); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Web.Extensions</AssemblyName>
<AssemblyVersion>3.5.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Object</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets the object that contains the data to insert.</summary>
<value>An object that contains the data to insert.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs.NewObject%2A> property contains the data that will be inserted into the data source. Create a handler for the <xref:System.Web.UI.WebControls.LinqDataSource.Inserting> event and retrieve the <xref:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs.NewObject%2A> property in order to validate the data, change the data, or cancel the insert operation before the data operation is executed.
The <xref:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs.NewObject%2A> property returns an object of type <xref:System.Object>. You can cast this object to the type of the class that represents the data.
## Examples
The following example shows a handler for the <xref:System.Web.UI.WebControls.LinqDataSource.Inserting> event. The object from the <xref:System.Web.UI.WebControls.LinqDataSourceInsertEventArgs.NewObject%2A> property is cast to a type named `Product`. The `DateModified` property of the `Product` object is set to the current date and time.
:::code language="csharp" source="~/snippets/csharp/VS_Snippets_WebNet/System.Web.UI.WebControls.LinqDataSource.Inserting/cs/Default.aspx.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_WebNet/System.Web.UI.WebControls.LinqDataSource.Inserting/vb/Default.aspx.vb" id="Snippet1":::
]]></format>
</remarks>
</Docs>
</Member>
</Members>
</Type>