Welcome
|
ASP.NET
|
Web Services
|
How Do I...?
|
Class Browser
| I want my samples in...
C#
VB
C++
J#
ASP.NET Quickstart Tutorials
Personalizing Using Web Parts
Introducing Web Part Controls
Creating Custom Web Parts
Editing Web Part Properties
Personalizing Web Parts
Connecting Web Parts
Adding Display Modes
Authorizing Web Parts
dd
Back to ASP.NET Home
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:
For each registered provider, the WebPartManager calls its provider connection point method.
The provider part creates a new instance of the communications interface, and returns it.
For each consumer registered for this provider, the WebPartManager calls its consumer connection point method, passing the interface instance.
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.
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
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
Log in to the page.
Select "Connect" from the dropdown.
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.
Click on "Create a connection to a Provider" link
Select Super cool user control" from the dropdown
Click connect
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
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
Log in to the page.
Select "Connect" from the dropdown.
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.
Click on "Create a connection to a Provider" link
Select Super cool user control" from the dropdown
Click connect
Click on "Create a connection to a consumer" link
Select "Untitle" from the dropdown
Click connect
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
Developer can create connection via code.
This example show how to Connect web Part using code.
Click on "Connect Web Part" button
Type text on the user control and click the button. The text that you typed should display on the Text Display Web Part
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
Developer can disable connection point at runtime.
This example show how to disable connection point at runtime.
Click the "Disable" radio button. this will break the connection between web parts
Click the "enable" radio button. this will restablish the connection between web parts
VB Disabling Connection Point