Home   |   QuickStart Welcome   |   ASP.NET   |   Web Services   |   How Do I...?   
  |   I want my samples in...      

ASP.NET 2.0 Quickstart Tutorials

Connections Between Web Parts

Web parts are also capable of exchanging data between them, using web part connections. Using connections, you can have one web part provide one or more property values that can be used by other web parts on the page. Web part connections have the following elements:
  • An interface that defines the communications contract between two parts. The interface describes properties and methods available through the connection.

  • A web part that behaves as a connection provider. To specify a provider connection point, a web part needs to have a method that creates and returns an instance of the communications interface. This method should be marked with the ConnectionProvider attribute. A single provider connection point can be used with multiple connection consumers.

  • A web part that behaves as a connection consumer. To specify a consumer connection point, a web part needs to have a method that takes an instance of the communications interface as a parameter. This method should be marked with the ConnectionConsumer attribute. A single consumer connection point can only be used with one connection provider.
You can connect web parts statically when you build the page, or allow parts to be connected dynamically by the user. At runtime, web part connections are managed by the WebPartManager, as follows:
  1. For each registered provider, the WebPartManager calls its provider connection point method.
  2. The provider part creates a new instance of the communications interface, and returns it.
  3. For each consumer registered for this provider, the WebPartManager calls its consumer connection point method, passing the interface instance.
  4. The consumer part calls properties and methods on the communications interface instance.
This example shows a connection between two web parts on the page. The part that displays text connects to the user control web part that allows text entry. The two parts exchange text through the ITextCommunication interface.

  1. Type text on the user control and click the button. the text that you typed should display on the Text Display Web Part
VB Static Connection
Run Sample View Source

A user can stablish connection between web parts by using the ConnectionZone. this type of connection are called dynamic connections.
This example show how to Connect web Part dynamically
  1. Log in to the page.
  2. Select "Connect" from the dropdown.
  3. Click the dropdown arrow on the Text Display Web Part's title bar, and select "Connect" from the menu. The ConnectionZone will now be visible.
  4. Click on "Create a connection to a Provider" link
  5. Select Super cool user control" from the dropdown
  6. Click connect
  7. Type text on the user control and click the button. the text that you typed should display on the Text Display Web Part
VB Dynamic Connections
Run Sample View Source


A Web Part can provide multiple connection point; as a result it can participate on multple connections.
This example show how to Connect web Part dynamically
  1. Log in to the page.
  2. Select "Connect" from the dropdown.
  3. Click the dropdown arrow on the Text Display Web Part's title bar, and select "Connect" from the menu. The ConnectionZone will now be visible.
  4. Click on "Create a connection to a Provider" link
  5. Select Super cool user control" from the dropdown
  6. Click connect
  7. Click on "Create a connection to a consumer" link
  8. Select "Untitle" from the dropdown
  9. Click connect
  10. Type text on the user control and click the button. the text that you typed should display on the Text Display Web Part as well as the number of lettler in the text
VB Multiple Connection Points
Run Sample View Source

Developer can create connection via code.

This example show how to Connect web Part using code.
  1. Click on "Connect Web Part" button
  2. Type text on the user control and click the button. The text that you typed should display on the Text Display Web Part
  3. Click on "Disconnect Web Part" button. The text that you typed should not be display on the Text Display Web Part
VB Connecting Web Parts using Code
Run Sample View Source

Developer can disable connection point at runtime.

This example show how to disable connection point at runtime.
  1. Click the "Disable" radio button. this will break the connection between web parts
  2. Click the "enable" radio button. this will restablish the connection between web parts
VB Disabling Connection Point
Run Sample View Source