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 created a list definition created from visual studio. I also have an event receiver specified along with the listtemplate feature. The idea was to have event receiver registered for all lists created from this definition. List and event receiver is working as expected (even for new lists created).

I noticed today that, if I access the SPList.EventReceivers.Count (via powershell/object model/ SP Manager), the count is always 0. But if I create new event receiver (new project) and bind it to the list, the assemebly shows up in SPList.EventReceivers

So my question is if I have a custom list definition with an event receiver why is the SPList.EventReceivers.Count 0 even though there is an event receiver attached to it.

Edit: Also verified using SharePoint Manager tool.

share|improve this question
add comment

3 Answers

up vote 5 down vote accepted

Finally traked it down.

The event receiver was listed under SPSite.EventReceivers.

As per msdn, the event receiver will be registered as per the scope specified (seems to default to feature scope). As my feature (which contained list template and event receiver) was deployed using scope=site, the event is listed under spsite.eventreceivers (registered event receiver to all lists of the specified list template type in the site collection).

Scoping the feature to web registered the receiver to all list of the particular web. SPList.EventReceivers had the specified event receiver name this time. Using ListUrl attribute instead of ListTemplateId registered the event receiver to a particular list instance.

Can someone add more information.

See Receiver element Schema

share|improve this answer
add comment

This might be a long shot, but when you created your list definition, did you bind the event reveiver to the actual list, or to a content type that you also created as part of the list definition?

share|improve this answer
    
I have binded using list template Id "<Receivers ListTemplateId="" >. It was deployed along with the same feature that deploys the corresponding list definition and it is working. But I am not sure if SPList.EventReceivers is supposed to be 0 (is it expected behaviour?) –  sssreddy Mar 21 '12 at 3:04
add comment

The simplest way (non-coded solution) is to download http://spm.codeplex.com/

you can run SharePoint Manager on your SharePoint server (make sure you do a 'run as administrator' for the first time), then just navigate to your appropriate list, and open up event receivers. It will display everything attached.

This is a great tool for determining precisely what exists where on your site, and i definitely recommend you get it, even if you prefer to come up with a coded solution for this particular problem.

share|improve this answer
    
Forgot to mention that, I did verify it with SharePoint manager tool. The property is empty. –  sssreddy Mar 21 '12 at 0:04
    
Do me a favor and check the content type definition in SharePoint Manager then, i just finished checking my dev server, but i dont have any event receivers set up that way –  Zork Mar 21 '12 at 0:21
    
Nope. Is empty. –  sssreddy Mar 21 '12 at 2:52
add comment

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.