As I had problems with the way events worked, I wanted to know more about the way they worked. below is bit of information about events that is good to know:
Two different kinds:
There are two different kinds of events: Synchronous and Asynchronous events.
* Synchronous events
- End with -ing (ItemAdding, ItemUpdating)
- Block the code as long the events arent finished
- Can (thus) make use of Session vars (HttpContext.Current is available)
- Can be used to prevent the event being finished. For example, with the ItemUpdating event you can verify the content being updated. Is the update not valid, the SPItemEventProperties.Cancel can be set to true and the SPItemEventProperties.ErrorMessage can be filled with an error message. This error message will not be displayed, but is written to the logfile. An error page will appear.
- dont contain the SPListItem in it's SPItemEventProperties (well, in the case of ItemAdding, that is, I didnt test it for the other events), so when you want to make changes to any of it's field you need to make use of the SPItemEventProperties.AfterProperties (see message below).
* Asynchronous events
- End with -ed (ItemAdded, ItemUpdated)
- Dont block the code.
- Can't (thus) make use of the Session (HttpContext.Current is null)
- Can't be reverted; When these events are fired, the item is already added, updated or deleted.
- contains the SPListItem. Changes can be made if you want to. This fires the (for example) ItemUpdating and ItemUpdated event. This can be turned off by using this.DisableEventFiring();
When creating a new list, events like FieldAdded and FieldAdding are not fired!
dinsdag 29 april 2008
Abonneren op:
Reacties posten (Atom)
Geen opmerkingen:
Een reactie posten