4

I have an ItemAdding event handler created and targeted to a Custom List. The event receiver seems to be firing on all custom list on the site. I wonder if I should target it to a specific custom list. Is this possible? or should I just leave it like it is now? If it's possible, how?

5

Navigate to corresponding Elements.xml, and you will notice Receivers element with ListTemplateId attribute, like this:

<Receivers ListTemplateId="100">
   ...
</Receivers>

What you need is to use ListUrl attribute instead, and point it to the specific list using provided url.

There is a how-to on this on MSDN:

Basic example:

<Receivers ListUrl="Lists/Test">
   ...
</Receivers>

Full schema of Receivers element could be found in Receivers Element MSDN reference article.

Also, the binding could be performed programmatically (usually in FeatureActivated receiver), using SPList.EventReceivers collection.

  • 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. – Amit Kumawat Jan 3 '12 at 17:31

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.