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

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 January 15, 00:25
How To Enable Target Value And Actual Value In #D3 Gauge Chart

Twitter January 15, 00:24
How To Open #SharePoint List Hyperlink Column In Modal #Popup Window

Twitter January 15, 00:24
Quick Introduction To #Asp.NetCore And It’s Features

Twitter January 15, 00:22
How To Configure #PerformancePoint Services To Use Secure Store In #SharePoint 2013

Twitter January 15, 00:21
How To Block Or Disable #Office365 Services

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