0

Within an item-adding event, suppose if we write code that creates new item, then item adding will fire twice.

Same is true for item-added, item-updating, item-updated, etc.

In such cases how can we handle in code?

The solution for item-updated/updating is (using try/catch for following):

this.EventFiringEnabled = false;
// Do the changes
item.Update();
this.EventFiringEnabled = true;

Can this method be used to handle every event receiver event to prevent from firing twice? Or am I confused with this concept?

2

no that code above is only required within the updating event.

Say i have an added event and updating/updated event.

when the added/adding event is triggered it will then trigger the updated/updating event. you can put the code within the item adding or added so that it doesnt trigger the updating event at the same time.

the point of the code is to stop the continuous loop, as an example.... i have code within added event that changes some value within a field. This triggers the updating event. that is fine! but when i have code within the updated event changing values within the list it would loop as your updating the item and then calling the same event because of the update and then updating the item (same code) and calling the same event because of the updating (code updating list).

the code:

this.EventFiringEnabled = false;
// Do the changes
item.Update();
this.EventFiringEnabled = true;

that stops the loop, basicly on the list it stops the event reciver calls so you can make your changes and then set the trigger back to the list so no events are called after changes are made.

the code would be based on your requirments but is mainly used within updating event due to looping but could be used within other events to stop over event calls if you dont want them to be called for some reason! like adding event triggers updating that adds items that calls adding event that calls updating ;)

  • no problem! happy to help. – Ali Jafer Aug 6 '14 at 10:20

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.