WPSC Services
Applies to: SharePoint Foundation 2010
The functionality of the Web Part Page Services Component (WPSC) is organized into services. There are multiple services, and each defines a scope of functionality that targets a specific purpose. For example, the Web Part Discovery Service enables Web Parts that are derived from the Microsoft.SharePoint.WebPartPages.WebPart class to detect other Web Parts at run time. The Web Part Notification Service sends and receives information about events occurring in various Web Parts or on a Web Part Page. A WPSC service is really a semantic creation—there is no binary aspect to a specific service.
A single Microsoft JScript file (IE50UP.JS or IE55UP.JS) contains functionality for all WPSC services. By itself, a service is just a way to identify a set of objects, collections, methods, and properties to use if you want to accomplish a specific goal. Any given object can play a role in numerous services. No object or collection is restricted to a specific service, and no object or collection encapsulates a service.
Following are descriptions of the services provided by WPSC: Discovery, Notification, and State Management.
Web Part Discovery Service
The Web Part Discovery Service provides a way for Web Parts to determine the presence of other Web Parts at run time, enabling you to create dependencies between Web Parts or to dynamically change a Web Part based on the state of another Web Part.
The Web Part Discovery Service detects whether other Web Parts are present in the Parts collection of the Web Part Page. After you determine that a Web Part is available, you can check its state and use the results to determine how you want a Web Part or Web Part Page to respond.
The Web Part Discovery Service enables the following scenario: Let's say you want to make an Order Web Part dependent upon a Customer Web Part, so that the Order Web Part is displayed only when the Customer Web Part is available. By enumerating the Parts collection, you can determine whether both are on the page. You can then check the Web Part state to determine a further course of action. For example, if Order is read/write, Customer is read/write. To use the Web Part Discovery service, you use the WPSC object, the WebPartPage object, the Parts collection, and one or more Part objects.
Web Part Notification Service
The Web Part Notification Service provides a standard multicast event mechanism for Web Parts that hides the complexity of the underlying event mechanisms of the Web browser, such as DHTML events. Through the Web Part Notification Service, Web Parts can register for an event, and then provide a function that is called when the registered event runs. Events occur if an object changes state. Such objects can be system objects (that is, static objects that have a fixed name, such as the WebPartPage object or the Parts collection), or custom objects that you define (for example, Customers or Contacts).
The scope of an event is a namespace that defines a context for the event. A Web Part can raise an event or respond to an event. Separating these two roles enables the coordination of Web Parts on a page. System and custom events are handled in the same way, which means that scripts can be simpler and Web Parts more encapsulated. It also makes it possible to surface session events from the browser or operating system.
State Management Service
The State Management Service provides the ability to access and modify the built-in and custom properties of a Web Part from the client at run time. The state of a Web Part is the combination of standard Web Part properties and any user-defined or system-defined extensions. For example, a Web Part that displays a stock ticker must be able to save and retrieve customization information between sessions. In this case, the stock symbols the user selects are private data. This data and the values from the Web Part schema that you specify constitute the state of the Web Part.
The State Management Service deals with state information for a particular Web Part. All access to a Web Part Page and Web Parts through the Parts collection retrieves state information based on the current view of the page. If you are in Personal mode, personalized information is retrieved; if you are in Shared mode, global information is retrieved. It is important to note that state information, whether personalized or global, is stored with the Web Part. If you delete a Web Part, its state information is lost.
See Also
Concepts
Client-side Programming Using the WPSC