SharePoint 2010 Cookbook: Creating Connections Between Web Parts

This article will guide you through how to create a connection between Web Parts. You can create connections between Web Parts so that when you want to perform an action in one Web Part, it changes the contents of another Web Part.


How can I create connections between Web Parts in SharePoint 2010?


The first things you should keep in mind when creating a connectable Web Part are:

  • Create an interface for data to be shared between Web Parts.
  • Create a provider Web Part (a method with ConnectionProvider attributes).
  • Create a consumer Web Part (a method with ConnectionConsumer attributes).

What follows are specific steps to create a connection between Web Parts, including code samples.

I. Creating an interface

This step is to create a class that implements all of the necessary methods and events for a connection interface.

1. In Solution Explorer, click the ConnectableWebParts project.

2. On the Project menu, click Add New Item.

3. In the Installed Templates pane, click Code and then create an Interface named ITextBoxString class. Make sure that the class is public:

public interface ITextBoxString


string TextBoxString { get; set; }


II. Creating a provider Web Part

This step is to demonstrates how to create a Web Part that provides a string for other Web Parts to consume.

1. In the Solution Explorer, create Connectable Web Part name StringProvider, expanding SharePoint node, and then click 2010 in the Installed Templates pane.

2. In the StringProvider.cs file, create a StringProvider class that implements the ITextBoxString interface:

public class StringProvider : WebPart, ITextBoxString

3. Then create a text box, a string, and a button:

private TextBox myTextBox;

private String _textBoxString = String.Empty;

private Button myButton;

4. Create properties of the ITextBoxString interface:


public string TextBoxString




return _textBoxString;




_textBoxString = value;



5. In the CreateChildControls method, clear all the controls from the Web Part, and then add the new control to the Web Part as follows:

protected override void CreateChildControls()



myTextBox = new TextBox();


myButton = new Button();

myButton.Text = “Change Text”;


myButton.Click += new EventHandler(myButton_Click);


6. Create an event handler for the button that you added in the previous step:

void myButton_Click(object sender, EventArgs e)


if (myTextBox.Text != String.Empty)


TextBoxString = myTextBox.Text;

myTextBox.Text = String.Empty;



7. Create a method with ConnectionProvider atributes to return the ITextBoxString object to share with other Web Parts:

[ConnectionProvider(“Provider for String From TextBox”, “TextBoxStringProvider”)]

public ITextBoxString TextBoxStringProvider()


return this;


III. Creating a consumer Web Part

This step is to demonstrates how to create a Web Part that consumes and displays a string from a provider Web Part.

1. Create Connectable Web Parts named StringConsumer right-clicking on the Project menu, then click Add New Item. In the Installed Templates pane, expand the SharePoint node, and then click 2010.

2. Open the StringConsumer.cs file, create objects for an ITextBoxString provider and a text box:

private ITextBoxString _myProvider;

private Label myLabel;

3. In the CreateChildControls method, add the label to the Web Part. The default text is set to indicate if the consumer Web Part is connected to the provider Web Part:

protected override void CreateChildControls()



myLabel = new Label();

myLabel.Text = “Default text”;



4. In the OnPreRender method, add the following code to change the text of the label to the string from the StringProvider class:

protected override void OnPreRender(EventArgs e)



if (_myProvider != null)


myLabel.Text = _myProvider.TextBoxString;



5. Create a method with ConnectionConsumer attribute to assign the ITextBoxString object from the provider Web Part to the private ITextBoxString object in this consumer Web Part:

[ConnectionConsumer(“String Consumer”, “StringConsumer”)]

public void TextBoxStringConsumer(ITextBoxString Provider)


_myProvider = Provider;


IV. Testing the Web Part connection

This step is to connect the provider and consumer Web Parts in your SharePoint site.

1. Open your SharePoint site.

2. Add the two Web Parts, StringProvider and StringConsumer, to your Web Part Page.

3. Click on the StringConsumer Web Part menu and point to Connections, then point to Get String Consumer From, and then choose String Provider.

4. In the StringProvider Web Part, type something in the text box, and click on Change Text button. Whatever string you type in the StringProvider will appear in the StringConsumer.


Source code is available upon request.

See Also:

SharePoint Online

The cloud parts are functional components that extend your SharePoint Online environment in Microsoft 365.

Supports Classic and Modern sites for SharePoint Online/Microsoft 365

Small Business Pricing and Discounts


Top SharePoint Online Products

Experience greater power and savings by bundling our SharePoint apps and cloud parts.

Calendar Plus


Employee Directory Plus

Org Chart Plus

Simple Search


Tree View


On-Premises Only

These web parts extend SharePoint beyond its out-of-the-box capabilities by tailoring it to your requirements with Bamboo Solution’s growing portfolio of SharePoint Web Parts.

SharePoint 2016, 2019, 2022 – Classic Pages Only


Top On-Premises Only Products

Experience greater power and savings by bundling our SharePoint apps and web parts.

Calendar Plus

Data Viewer

Password Change

Password Expiration

Password Reset


Our team of Microsoft 365 Technology Consultants helps you get the most out of your Microsoft technology, we have the best Microsoft 365 talent to streamline your organization.

Consulting to Streamline Your Department

M365 Plus

Managed Services

Microsoft 365

Consulting to Streamline Your Department

Human Resources

Information Technology

Marketing Campaigns




Our Consultants Have What You Need

Federal Contractors