14.2. The Web Part Page Event Model

WPSC notification services are embodied by the SharePoint Web Part Page event model. An event is something that happens that might be interesting to the components on a page. Letting the WPSC know that this has happened is called raising the event.

There are many different events that can be raised on a page. Some are generated by the system; others can be generated by user interaction, or even by your own code. Whatever the source, you can write code to respond to the events. If you want to respond to an event in your code, you register for it with the WPSC.

How does this help? In the search example in chapter 13, you saw how a script in one Web Part could directly call a function that resided in a different part. While convenient, this direct-access model is fraught with difficulties:

  • You need to know the exact name of the function you are trying to call.

  • If a part containing that function is not on the page, your script generates an error.

  • If you need to make changes in multiple Web Parts, you must call all of the relevant part-specific functions.

  • You need to be concerned that you do not have naming conflicts between the various functions.

With the event model, all of these problems go away. Raising an event provides benefits for the calling function, and registering for the event benefits the functions being called:

  • Interfaces (namespaces and event names, and optionally a parameter) can be set early, without regard to the actual implementation ...

Get Professional Microsoft® SharePoint® Designer 2007 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.