Wednesday, June 17, 2009

How to create connected web parts: Part 1

While this may be lengthy, my hope is that this is made as easy as possible. I begin this with a high level overview of connected web parts (Part 1), followed by a step-by-step tutorial on creating connected web parts where all you need to do is click along and paste code (Part 2).

Let's say you have two web parts: one that takes a zip code and displays the weather for that zip code, and another web part that takes a zip code and displays movies playing in movie theaters in or near that zip code. They both require a zip code textbox with appropriate validation. Plus, what if you need to develop another web part that also requires a zip code and then displays other information based on that zip code?

Eliminate redundancy and welcome connected web parts! Instead of the above, we could make a zip code web part which acts as a provider, providing a zip code to another web part. Then our weather web part and movie web part could act as consumers, consuming a zip code fed to them by the zip code provider web part.

Essentially, this involves creating a zip code interface that all three web parts will understand. Then we make each web part, specifying in the code that the zip code web part is a provider web part while specifying the weather and movies web parts are consumer web parts.

Once the web parts and interface are built and deployed to a SharePoint site, a user can add the zip code web part to a page, add the weather web part to a page, then finally connect the two web parts via the Modify Shared Web Part option for either web part.

In Part 2 of this post is a tutorial on how to create Contact List/Email Contact connected web parts, along with entire code to be copy and pasted. I recommend following the tutorial to get the web parts functional, then look at the comments in the code to understand what everything is doing. Also, I will include a summary explaining the details of whats happening. Good luck!

1 comment: