I have created two webparts via Visual Studio. After taking the connections option in the SharePoint UI, I'm able to connect between webparts. Is there any way to set the connections completely in the visual studio code itself ?


In SharePoint, a web part can be 'connected' to another web part to provide some information at run-time. The Provider web part pushes out the contracted information and the Consumer web part is set up to receive and consume the shared information.

This functionality lends to setting up a combination of simple web parts which may have been developed separately, into a functional and re-usable solution.


(1) Interface

a. This custom interface will define the data to be shared from the Provider to the Consumer web part.

(2) Provider web part

a. Inherits from Microsoft.SharePoint.WebPartPages.WebPart

b. Implements a data interface - this interface is a definition of the data that will be shared from the Provider web part to the Consumer web part.

c. Provide mechanisms for user selection of the interfacing data

d. Provide a ConnectionProvider method which will expose the interfacing data to the Consumer web part.

(3) Consumer web part

a. ConnectionConsumer method which will receive the interfacing data

b. 'Consume' the interfacing data and provide enriching details to the user.

you can also do it using SPLimitedWebPartManager to connect the Web parts with ASP.NET style interfaces.

Follow the steps in the below URL to do your requirement,

  1. Connecting Custom Web Parts in SharePoint

  2. Connected Web Parts in SharePoint 2010 - an Architectural Framework

  3. Walkthrough: Creating Connectable Web Parts in SharePoint

  4. Connectable Web Parts in SharePoint 2010

  5. Complete Code of SharePoint 2007 (MOSS/WSS) Connected Web Parts using IWebPartField Interface

I haven't tried with Visual Studio, but the following approach will be helpful to do your requirement,

We can create a static Web Parts connection between two server controls by declaring the connection in page persistence format. A static connection becomes a permanent object on a Web page, like a declared control. All users can see a static connection (because it is a shared object), and they can never delete the connection object, although they can disconnect it if provided with the user interface (UI) options for doing so. Static connections are a good option when you want a connection that is always available to all users, and you do not want users to have the option of deleting it from the page.

Declare a Static Connection between Two Web Parts Controls

  • I have connected the webparts and its working fine. But, sometimes when I take the page, it get redirected to the home page. In ULS logs, not much info was there... See this msg.. Orphaning WebPart with id g_76cd0982_9a0c_418c_a50b_0154a1b99981 on Page esiadsspdplot2:4444/Pages/home.aspx?ReturnUrl=/Pages/…. Any idea about this error ?
    – Anish V
    Dec 12 '13 at 13:24

Yes, You can connect your webparts programmatically, below are good links to achieve your goal:



  • Please do not only provide links as answer, extend your answer with the important bits from your links. If the links break, your answer will not be very helpful as it looks now :) Dec 11 '13 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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