Synchronous vs Asynchronous Event Receivers
- Synchronous - Events are executed before the action is executed on the content database.
Events ending with -ing are named as Synchronous Event Receivers Ex. Item Deleting,Item Adding.
2. A Synchronous - Events are executed after the action is executed on the content database.
Events ending with -ed are named as A Synchronous Event Receivers Ex. Item Deleted,Item Added.
Different Base Classes in Event Receivers:
There are totally 5 base classes in SharePoint 2010,
Events ending with -ed are named as A Synchronous Event Receivers Ex. Item Deleted,Item Added.
Different Base Classes in Event Receivers:
There are totally 5 base classes in SharePoint 2010,
- SPItemEventReceiver – Event at List item Level.
- SPListEventReceiver - Event at List Level.
- SPFeatureEventReceiver - Event activation and Deactivation at list level.
- FeatureInstalled: Right after feature is installed.
- FeatureActivated: Right after feature activation through “Site Settings” or otherwise.
- FeatureDeactivated: Right after feature deactivation through “Site Settings” or otherwise.
- FeatureUninstalled: Before feature is uninstalled.
- SPEmailEventReceiver :Event to send mail to list
- SPWebEventReceiver : Event at Web Site Level.(Site added,site deleted,etc..)
Disabling and Enabling the event Receiver
If we are modifying/updating the same List item using event receiver,then the event receiver is triggered again and again.So you have to prevent it from firing before you update changes to the list item. We can implement this functionality using EnableEventFiring attribute to true/false.
Example:
public override void ItemAdded(SPItemEventProperties properties)
{
//will disable the event receiver
EventFiringEnabled = false;
//do some action on list like update List.Update()
//will enable the event receiver
EventFiringEnabled = true;
}
Comments
Post a Comment