1

Can anyone tell me that how can i disable an event receiver on one SharePoint list while adding an item in other?

For example i want to disable event receiver on list B while i add item in list A.

I have event receiver registered on both the list. What happens is when i add item in List A the event receiver for this list gets triggered and adds item in List B but on the same time the event receiver on List B gets triggered and adds item in list A,this creates an infinite loop.

i want to break this loop such that when an item is added in list A it disables the event receiver on list B and stops the loop.

how can i do that ?

1

In your Event Receiver set SPEventReceiverBase.EventFiringEnabled to false while performing actions which should not trigger other Event Receivers

1

You can place code something like as below:

public override void ItemAdding(SPItemEventProperties properties)
{
    try
    {
        bool allowed = true;

        if (properties.ListTitle == "List A")
        {
           allowed = checkItem(properties);
           // Place your code for item adding for list A
        }

        if (!allowed)
        {
           // Your code when List is different.
        }
    }
    catch (Exception ex)
    {
        properties.Status = SPEventReceiverStatus.CancelWithError;
        properties.ErrorMessage = ex.Message;
        properties.Cancel = true;
    }
}

This is the example for ItemAdding event, you can place this code same way in ItemAdded event also. Refer this example for more: Creating SharePoint 2010 Event Receivers in Visual Studio 2010

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.