Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

ItemEventReceiver doesn't fire under subsite or sub-workspace

  Asked By: Jasmin    Date: Aug 24    Category: Sharepoint    Views: 1883

I created a custmized content type attachment to a task list and
I registered them in the FeatureReceiver file as following:
-------------------------------------------------------------------------------\
----------------
SPSite siteCollection = (SPSite)properties.Feature.Parent;
SPWeb site = siteCollection.RootWeb;
SPList TaskList = site.Lists["CustomTaskList"];
string asmName = "CustomTaskList, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=9e12c90f143615b6";
string listReceiverName = "CustomTaskList.CustomTaskListEventReceiver";
string itemReceiverName = "CustomTaskList.CustomTaskItemEventReceiver";
// add event receiver to fire before new column is added
TaskList.EventReceivers.Add(SPEventReceiverType.FieldAdding,asmName,
listReceiverName);
-------------------------------------------------------------------------------\
----------------
The event works fine when the list created under root level. But after I created
the same list with the same content type under a sub workspace or subsite, the
event never fired. I also tried to registered event receiver to the content type
instead list in the FeatureReceiver.cs and it still didn't work. I deploied the
solution to the root and I marked EnableContentTypes=True in the schema.xml.
Please, any suggestion or idea why the event of the list not fired under subsite
or sub-workspace is grateful.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Mark Davis     Answered On: Aug 24

Your code only activates the event  reciever on the TaskList in the root  web
site. You need to activate it in every list/web site  where you want it to fire.
Event Receivers can't be attached to content  types, only to lists, webs, etc.

 




Tagged: