Event receivers in sharepoint 2010

Event receivers in SharePoint 2010:

An event receiver is a class that contains one or more methods known as event handlers that are executed automatically by SharePoint in response to events such as adding item to a list. 
You can use event handlers for data validation, data integrity etc.

SharePoint categories events into of two types 1. Before events (synchronous events) 2. After events (asynchronous events).
1. Before events (synchronous events):

These events fires before an action occurs and before SharePoint has written any data to the content database.
For example ItemAdding event will fire when trying to add an item to a list. These events does support cancelling of event action. These events are always end with 'ing' like FieldAdding, ItemAdding, ItemUpdating, WebAdding, WebDeleting etc. These events are also know as synchronous events.

 2. After events (asynchronous events):

These events fire after the event action has completed and after SharePoint Foundation has written to the content database to commit the event action. These events does not support cancelling of event action. These events does support cancelling of event action. These events are always end with 'ed' like FieldAdded, ItemAdded, ItemUpdated, WebAdded, WebDeleted etc. These events are also know as asynchronous events.

Example:

See the following example, In timer job creation process We are inheriting event receiver from SpFeatureReceiver class, and using event handlers like FeatureActivated,FeatureDeactivating.


For more details see this link

Comments

Popular posts from this blog

Upload Single/Multiple file by using the REST API and jQuery SharePoint 2013

A type named 'SP.Data. could not be resolved by the model error

Add content type to SharePoint List/Library using REST API