Registering SharePoint Event Receivers that are already registered

mosssharepointwss

I am writing a web part against a list. The first thing I do in the web part is verify that my custom event receivers are registered on the list. If they are not, I register the programmatically.

I have noticed that if I try to register an event that is already registered, I get no errors and no “Extra” events are registered.

My question is: Would it be more efficient to just register the events each time the web part loads rather than iterating through each event in the event receiver list and doing compares to see if each of my event receivers are there?

Edit

About the Property bag suggestions. After thinking a bit more about it, this will not be a feasable solution. The reason that I am "verifying" that the receivers are there is because we have 3rd party webparts that are attached to the same list. These have, in the past, actually unregistered our custom receivers. Setting a flag in the property bag will just let me know that I have verified once, but won't tell me if they get removed by another.

Best Answer

The code that SharePoint uses to update an event receiver collection is obfuscated, so there's no way to know for sure. I would guess that the first step is a check similar to what you are doing manually. I'm inclined to go with what's easiest until you identify that performance is an issue, in which case I would set a flag on the list's RootFolder's property bag.

Related Topic