Share via


Client-side Communication

To allow for richer interactions and better performance, Web Parts can connect through interfaces on the client as well as on the server. Client-side connections are processed in the browser on the client computer. The Web Part Page Services Component (WPSC) on the client is used as a router that brokers event communication. This differs from the server side, where the Web Part infrastructure simply hooks up events.

In the client-side case, the WPSC always receives the event, and passes it to every part that has both a registered event handler for it and a connection between the sending and receiving part.

In addition to calling the PartCommunicationConnect method, the Web Part infrastructure calls the following three methods if they exist on the Web Part: PartCommunicationInit, PartCommunicationMain, and GetInitEventArgs.

  • A Web Part that implements a connection interface must override PartCommunicationConnect. This method runs on the server and notifies the Web Part that it is connected. Relevant information is passed to the connecting Web Part, such as the interface it is connected over, the Web Part it is being connected to, and whether the part will run on the client side or the server side. For client-side connections, parts are then rendered back to the client along with the appropriate client-side code.
  • The part developer should fire init events during PartCommunicationInit, and fire all other events during or after PartCommunicationMain. For example, in the IListProvider interface, the developer can fire the PartialListReady event during PartCommunicationMain, and then fire the ListReady event at a later time. Parts need to implement these methods on the client only if they have something they want to do during init or main. For client-side connections, the Web Part infrastructure calls into script in the browser.
  • Similarly, the part developer should return the InitEventArgs object for the interface being implemented when the GetInitEventArgs method is called by the infrastructure. The GetInitEventArgs method can be implemented on either the client or server, regardless of where the connectable Web Parts are running.

Note  In the case of the IFilterConsumer interface, the part developer only needs to implement the PartCommunicationInit method and not the PartCommunicationMain method.

For an example of how to create a connectable Web Part that can run on the client side, see Creating a Connectable Web Part. For more information about the Web Part Page Services Component (WPSC), see Web Part Page Services Component (WPSC) Overview.