Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ContextCreating Event

LinqDataSource::ContextCreating Event

Occurs before an instance of the context type object is created.

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

public:
 event EventHandler<LinqDataSourceContextEventArgs^>^ ContextCreating {
	void add (EventHandler<LinqDataSourceContextEventArgs^>^ value);
	void remove (EventHandler<LinqDataSourceContextEventArgs^>^ value);
}

By default, the LinqDataSource control creates an instance of the type that is specified in the ContextTypeName property. The LinqDataSource control calls the default constructor of the data context object to create an instance of the object. It is possible that you have to use a non-default constructor or you have to create an object that differs from the one specified in the ContextTypeName property. In that case, you must handle the ContextCreating event and manually create the data context object.

The context type object is created during select, update, insert, and delete operations.

There is one time when the event is not raised. This is when you programmatically set the Result property to an object in an event handler for the Selecting event. An additional condition is that either the original values do not have to be stored in view state, or the object in the Result property implements the ITable interface.

The following example shows how to create the data context object by using a non-default constructor during the ContextCreating event. The code assigns the object to the ObjectInstance property.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5
Show:
© 2015 Microsoft