Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have created a list item event receiver(ItemUpdated).

When a item is updated in a list(for which event handler is attached),my code updates other items (may be more than 1) in lists in subsites.

When I debug the event receiver,I see that the ItemUpdated is called many times even if I update a single item in a list to which event handler is attached.

The code is working fine but I am not sure why ItemUpdated is called multiple times,even if a single item is updated.

Any idea?

Update : I install the eventhandler using xml below:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListUrl="Lists/NewIdeas">
    <Receiver>
      <Assembly>.....</Assembly>
      <Class>......</Class>
      <Type>ItemUpdated</Type>
      <Name>....</Name>
      <Synchronization>Synchronous</Synchronization>
      <SequenceNumber>1000</SequenceNumber>
    </Receiver>
  </Receivers>
</Elements>
share|improve this question
1  
are you sure that the other lists you are updating don't have similar event receivers acting on them to update the original list item? –  Zork Mar 28 '12 at 12:55
    
Please provide more information on how you installed event handlers –  Amit Kumawat Mar 29 '12 at 5:09
    
@AmitKumawat, See my edit above –  SP.NET Mar 29 '12 at 8:52
    
What is the scope of your feature that installs the event receiver (using above xml) –  Amit Kumawat Apr 2 '12 at 8:35
    
The scope is at 'Site' level –  SP.NET Apr 2 '12 at 8:41

2 Answers 2

up vote 14 down vote accepted
+50

I think the problem is in the way you installed the event receiver.

"ListUrl" works only if feature has Scope=”Web”. In case the feature has Scope=”Site”, event receiver is fired for every list, ListUrl is ignored. Check this for more details : http://extreme-sharepoint.com/2011/12/27/event-receivers-sharepoint-2010/

So, in your case the event receiver is attached to every list and hence the problem.

The solution is to change the scope from "Site" to "Web". Remember to disable and uninstall the current feature first.

share|improve this answer
    
Thanks for the answer! I have installed the feature with scope="Web" and now it is firing only for the list mentioned in url. –  SP.NET Apr 2 '12 at 11:22
    
I'd always recommend that you compare the event method "properties" variable for (properties.ListTitle.ToLower() != "your list name") to ensure that you simply ignore the handler in the event that you have misconfigured your feature. –  Brian Scott Apr 3 '12 at 14:39

If I understand correctly your event receiver updates item in the list that has the same event receiver. Thus your receiver updates item, item is updated, receiver is called, receiver update item, item is updated.... and so on... To solve this issue you can disable event firing in your receiver by this code:

public static void SystemUpdate(this SPListItem item, bool incrementListItemVersion, bool doNotFireEvents)
{
    SPItemEventReceiverHandling rh = new SPItemEventReceiverHandling();
    if (doNotFireEvents)
    {
        try
        {
            rh.DisableEventFiring();
            item.SystemUpdate(incrementListItemVersion);
        }
        finally
        {
            rh.EnableEventFiring();
        }
    }
    else
    {
        item.SystemUpdate(incrementListItemVersion);
    }
}

internal class SPItemEventReceiverHandling : SPItemEventReceiver
{
    public new void DisableEventFiring()
    {
        base.DisableEventFiring();
    }

    public new void EnableEventFiring()
    {
        base.EnableEventFiring();
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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