SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm prototyping the best way to dynamically connect web parts at runtime. Essentailly, the application will allow for several disparate application groups to create web parts that will be consumed within the SharePoint front end. All of the web parts will need to automatically detect consumers and providers to create connections at runtime.

What we are looking to do is have webparts discover and automatically connect to other compatible webparts. When a user adds the two compatible parts to a page, the parts should be able create the appropriate connections. We have a well defined interface for passing data between the parts, so the only issue is how to manage the connections. To be clear, we do not want user's to worry about having to create connections themselves.

For our purposes "best way" means most efficient, elegant and/or standard. We'd like to follow established sharepoint design patterns as much as possible, but code efficiency is somewhat important.

I've been able to draft a proof of concept that uses a base web part class to do this during the oninit event of each subclassed webpart. The oninit event grabs the current page's SPWebPartManager and itereates through each part creating consumer and provider connections for every webpart inheriting from the base class:

SPWebPartManager spManager = SPWebPartManager.GetCurrentWebPartManager(Page) as SPWebPartManager;
foreach (BaseWebPart provider in parts)
    foreach (BaseWebPart consumer in parts)
        if (provider != consumer)
            string connectionId = string.Format("WebPartConnection{0}{1}", consumer.ID, provider.ID);
            SPWebPartConnection conn = spManager.SPWebPartConnections[connectionId];
            if (conn == null)
                conn = new SPWebPartConnection()
                    ID = connectionId,
                    ConsumerID = consumer.ID,
                    ConsumerConnectionPointID = "WebPartConnectableConsumer",
                    ProviderID = provider.ID,
                    ProviderConnectionPointID = "WebPartConnectableProvider"
            connectionCreated = true;
share|improve this question
if you try to describe what you want to achieve, instead of the technical architecture, we might be able to help you better and maybe suggest alternatives :-) – Anders Rask Jun 15 '10 at 18:37
Particularly a definition of "best way" would be helpful. – Alex Angas Jun 16 '10 at 0:02
I've updated the question / post as best I can at this point. I fear my that coming from a pure development background and being somehwat new to sharepoint development may be hindering my ability to express the question in a meaningful way. – etc Jun 16 '10 at 10:16
up vote 0 down vote accepted

The WPSC has a publish/subscribe event model that will likely help. (In this model, providers always raise the event, even if no subscribers are on the page.)

Refer to the WPSC reference, in particular, the RegisterForEvent and RaiseEvent methods.

share|improve this answer
It appears that this is only client side, but very powerful stuff. Thanks! – etc Jun 23 '10 at 10:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.