SharePoint Pals
 | Sign In
How to Disable Events from Firing on SharePoint 2013
by Sathish Nadarajan 2 Nov 2014
SharePoint MVP
Today  :   18     Total  :    12686

As long as we are in to SharePoint 2013 development, we would have come up with the Event Receivers. There are certain scenarios that we will be writing ItemUpdated Event. Again that is based on the business requirement. But there could be a situation like, on the ItemUpdated itself, we will be updating the same list item.

In detail, I have a list which has an ItemUpdated Event Receiver (Custom one, which developed by the developer). On the event receiver, we are trying to update some of the columns based on the entered column value. i.e., based on Column1, I am calculating the value for the Column2 and update the list item on the Event Receiver. In that case, what happens is, again and again, the Event Receiver triggers as ends up with a bottle neck.

To avoid this, we can disable the event firing before updating the List Item on the Event Receiver. After completing our updates, we need to toggle back the property.

The properly from the SPItemEventReceiver class is

 base.EventFiringEnabled = false;

As a developer, for sure, we will forgot to toggle back this properly. To avoid that, let us come up with a Class and use that class with a “Using” Statement.

The simple class would be like

 public sealed class DisableEventFiring : SPItemEventReceiver, IDisposable
         bool _originalValue;
         public DisabledEventsScope()
             // Save off the original value of EventFiringEnabled 
             _originalValue = base.EventFiringEnabled;
             // Set EventFiringEnabled to false to disable it 
             base.EventFiringEnabled = false;
         public void Dispose()
             // Set EventFiringEnabled back to its original value 
             base.EventFiringEnabled = _originalValue;

The above class, I made it as sealed to avoid exceptions on the MSOCAF report generation. (MSOCAF – Microsoft SharePoint Online Code Analysis Framework). This ensure that, this class cannot be inherited.

Now, let us see, how to use this.

 public override void ItemUpdated(SPItemEventProperties properties)
 using (DisabledEventsScope scope = new DisabledEventsScope())
 //Update the Columns on the ListItem here.

As long as the Scope is active, no other events will get triggered.

Note: This will cause the Event Firing disabled on the Site Collection Level. Hence, None of the events would be triggered on this duration. As there is no other option, to disable specifically, we need to live with this. But anyhow, our ItemUpdated event may not be executed more than few milli seconds. With this assumption, we are proceeding.

Happy Coding.

Sathish Nadarajan.

blog comments powered by Disqus

SharePoint Pals

SharePoint Pals, a community portal for SharePoint developers, Administrators and End Users. Let's join hands and share the point together.
Read this on mobile


Angular Js Training In Chennai
Advanced Angular Js training with real world developer scenarios
Angular Js, Web Api and Ionic for .Net Developers
All in one client side application development for .Net developers
Angular Js For SharePoint Developers
Get ready for the future. Its no more just C#

Get Connected

SharePoint Resources

SharePoint 2013 and 2010 Web Parts
Free Web Parts with Source Code for SharePoint Community

SharePoint 2013 Books and Tutorials
Collection of free SharePoint 2013 books and tutorials (eBooks, pdfs)

Supported By

Contribute your article and be eligible for a one month Free Subscription for Plural Sight. The Author of the most popular New Article (published in the previous month) will be awarded with a Free One month Plural Sight Subscription. Article can be sent to in a word document.

Related Resources

Recent Tweets

Twitter October 21, 21:34
How to Add a JS Link Reference to the Display Form or Any other ASPX Programmatically using CSOM PNP in SharePoint -

Twitter October 20, 13:01
How to Add a JS Link Reference to the NewForm and EditForm Programmatically using CSOM PNP in SharePoint Office 365-

Twitter October 12, 12:15
How to Deploy Provider Hosted Apps (Add-Ins) by App Stapling in SharePoint Office 365 -

Twitter October 11, 13:39
How to Deploy Provider HostedApp programmatically using CSOM in SharePoint Office 365 Activating Developer Feature -

Twitter October 10, 09:26
How to Use Angular HTTP Services in SharePoint List -

Follow us @SharePointPals
Note: For Customization and Configuration, CheckOutRecent Tweets Documentation