Understanding Lists and List Item Event Receivers

In Hour 8, “Understanding Client Object Model in SharePoint 2010,” you learned how SharePoint enables you to hook the events in the life cycle of a SharePoint site collection and a SharePoint site through various event receivers provided by SharePoint. This section looks at the event receivers for a list and for list items. The event receivers for a list and list items can be categorized in two ways. One is the event receivers that get called when an event is happening and before it is completed. For example, the FieldAdding event is called before a new field is added to the list, and the ItemAdding event gets called before a new list item is created. Similarly some event receivers get called after the event has happened. For example, the FieldAdded event receiver gets called after a new field has been added to the list, and the ItemAdded event receiver gets called after a new list item has been created. You will find that the name of Before events end with “ing” and the name of the After events end with “ed.”

The other way to categorize events is synchronous events and asynchronous events. The ItemAdding event occurs synchronously, which allows you to set the Cancel property of the event argument to the item creation. The ItemAdded event on the other hand is called asynchronously after the item has been added. This means the user might sometimes see the added list item before the ItemAdded event receiver has been processed or at times after it is processed.

Table 11.1 lists the various events for a SharePoint list. Notice that the names of most of these events are self-describing.

Table 11.1. List Events

Image

Note that these event handlers are defined in the SPListEventReceiver class, which is the class that provides methods to trap events that occur for lists. This class is never instantiated, and your event receiver class inherits from this class and overrides the require methods.

Table 11.2 lists the various events for a list item.

Table 11.2. List Item Events

Image
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset