WebPartManager.ConnectWebParts Method (WebPart, ProviderConnectionPoint, WebPart, ConsumerConnectionPoint)
Assembly: System.Web (in system.web.dll)
public:
WebPartConnection^ ConnectWebParts (
WebPart^ provider,
ProviderConnectionPoint^ providerConnectionPoint,
WebPart^ consumer,
ConsumerConnectionPoint^ consumerConnectionPoint
)
public WebPartConnection ConnectWebParts ( WebPart provider, ProviderConnectionPoint providerConnectionPoint, WebPart consumer, ConsumerConnectionPoint consumerConnectionPoint )
public function ConnectWebParts ( provider : WebPart, providerConnectionPoint : ProviderConnectionPoint, consumer : WebPart, consumerConnectionPoint : ConsumerConnectionPoint ) : WebPartConnection
Not applicable.
Parameters
- provider
A WebPart control that has the role of furnishing data to another connected control.
- providerConnectionPoint
A method that serves as a callback method for the connection. As implemented in the Web Parts control set, this is a public method in provider that is marked with a ConnectionProvider metadata attribute.
- consumer
A WebPart control that has the role of receiving data from provider, and then processing or displaying it.
- consumerConnectionPoint
A method that connects with providerConnectionPoint to receive the data for the connection. As implemented in the Web Parts control set, this is a public method in consumer that is marked with a ConnectionConsumer metadata attribute.
Return Value
A WebPartConnection that contains the various information about the provider and the consumer needed for a connection.| Exception type | Condition |
|---|---|
| The WebPartManager control's collection of dynamic collections is read-only. |
The ConnectWebParts(WebPart,ProviderConnectionPoint,WebPart,ConsumerConnectionPoint) overload is used to connect controls when their connection points are sufficiently compatible that they can connect without using a WebPartTransformer object. When this overload of the method is called, it simply passes the call to the other overloaded version of the method, and passes a null reference (Nothing in Visual Basic) for the parameter that requires a WebPartTransformer object.
When you attempt to connect two controls programmatically, you can use the CanConnectWebParts method in a conditional check to determine whether the controls can be directly connected.
The following code example demonstrates how to use the ConnectWebParts method to create a connection programmatically. For the full code required to run the example, see the Example section of the WebPartManager class overview. From that example, you will need the source code for the user control that allows you to change display modes on the page, and the source code for the two custom WebPart controls.
The code for the Web page that hosts the two controls follows. The page uses Register directives at the top to declare the user control and the custom controls. The custom controls are then referenced declaratively within an <asp:webpartzone> element. The code that handles the Button1_Click method creates a connection between the controls by using the ConnectWebParts method.
After you load the page in a browser, click the Connect WebPart Controls button to form the connection. You can then enter some data in the text box, and click the Enter 5-digit ZIP Code button to demonstrate that the controls are connected, and that data entered in the first control is updated in the second.
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.