April 19, 2019
Hot Topics:

Establishing ASP.NET 2.0 WebPart Communication

  • August 11, 2006
  • By Sahil Malik
  • Send Email »
  • More Articles »

Establish the communication

You establish communication by specifying its details in one of three ways:

  1. Declaratively using the <StaticConnections> element in the WebPartManager
  2. Programmatically using the ConnectionPoint, ConsumerConnectionPoint, and ProviderConnectionPoint classes
  3. Pointing and clicking through a browser UI using the Connections Zone

This article demonstrates using Option #3 to set up communication.

Assuming that you have already set up a WebPart framework (my previous article demonstrated how), add a connections zone to your Web page:

<asp:ConnectionsZone ID="ConnectionsZone1" runat="server"/>

Also, add the Consumer and Provider WebParts to the DeclarativeCatalogPart:

<asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1"
      <cc4:TheConsumer ID="TheConsumer"
         Title="Communication Consumer"
         Description="This consumes the text."/>
      <cc4:TheProvider ID="TheProvider"
         runat="server" Title="Communication Provider"
         Description="This provides the text." />

Now, run the Web application, and add an instance of the Consumer and an instance of the Provider to WebPartZone(s) on an aspx page. See the WebParts with the WebPartManager in Catalog DisplayMode below:

Now, set the page in "Connect" DisplayMode. You should see "Connect" verbs appear next to the WebPart title bars as shown below:

Click on "Connect" for either WebPart. The processes for the consumer and the provider are essentially reversed, so just click on the provider's connect for this example, and experiment with the connect verb of the consumer at your convenience.

When you click on "Connect" for the provider, you should see a UI similar to the following appear in the ConnectionsZone:

Click on "Create a connection to a consumer" and choose the Communication consumer as shown below:

Next, you see the connections zone UI change to the following:

Also, notice that the Communication Consumer now shows the text value held by the Communication Provider:

Put the page in "Browse" display mode, change the "Sample Text" to "Extraordinary Text," and click "Update Text." You should see the two WebParts communicating with each other as shown below:

Congratulations. You've just established communication between two WebParts.

Further Steps

WebPart communication is an incredibly powerful tool that allows you to build complex and functional Web sites using various widgets. Also, you could wrap the WebPartZone inside an Atlas UpdatePanel and remove all postbacks involved in such communication. With a little style sheet magic, you could show a WebPartZone that holds the consumer as a popup. For example, you could create a WebPart that receives an English word, queries a dictionary over a Web service, and displays its meaning in a popup. Then, all WebParts that display content on a Web page could respond to double clicks and show a pop-up dictionary to the end user. Not only that, you could show tracking information for packages, live maps for addresses, and any other information that may make sense to communicate between WebParts.

The best part is that, once you have established a WebPart framework and a number of functional WebParts, you could set up such Web sites through a browser UI at runtime—just like SharePoint 2007. Thus, it isn't surprising that SharePoint 2007 can make good use of the ASP.NET 2.0 WebPart framework connections.

About the Author

Sahil Malik (www.winsmarts.com) has worked for a number of top-notch clients in Microsoft technologies ranging from DOS to .NET. He is the author of Pro ADO.NET 2.0 and co-author of Pro ADO.NET with VB.NET 1.1. Sahil is currently also working on a multimedia series on ADO.NET 2.0 for Keystone Learning. For his community involvement, contributions, and speaking, he has also been awarded the Microsoft MVP award.

Page 2 of 2

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date