SharePoint: Disable event firing from non event handler code.

While working recently on a new project I needed to Disable event firing from MOSS 2007 custom layouts page. I came across this article of Sohel. The article shows how to do it in SharePoint 2010. The following lines of code show how we can disable event firing in MOSS 2007.


public class EventReceiverManager : SPEventReceiverBase, IDisposable
{
    public EventReceiverManager(bool disableImmediately)
    {
        if (disableImmediately)
        DisableEventFiring();
    }

    public void StopEventReceiver()
    {
        DisableEventFiring();
    }
    public void StartEventReceiver()
    {
        EnableEventFiring();
    }

    public void Dispose()
    {
        EnableEventFiring();
    }
}




While in Layouts page we can call the item.Update() or   item.SystemUpdate() as follows:

item["ColumnName"]= "New value";
using (var eventReceiverManager = new EventReceiverManager(true))
{
    item.SystemUpdate();
}