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;
  • 1
    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 :-) Jun 15, 2010 at 18:37
  • Particularly a definition of "best way" would be helpful.
    – Alex Angas
    Jun 16, 2010 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, 2010 at 10:16

1 Answer 1


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.


  • It appears that this is only client side, but very powerful stuff. Thanks!
    – etc
    Jun 23, 2010 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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