WebPartManager::CanConnectWebParts Method (WebPart^, ProviderConnectionPoint^, WebPart^, ConsumerConnectionPoint^)
Checks the WebPart controls that will be participating in a connection to determine whether they are capable of being connected, when the consumer and provider controls have compatible interfaces and a WebPartTransformer object is not needed.
Assembly: System.Web (in System.Web.dll)
public: bool CanConnectWebParts( WebPart^ provider, ProviderConnectionPoint^ providerConnectionPoint, WebPart^ consumer, ConsumerConnectionPoint^ consumerConnectionPoint )
Parameters
- provider
-
Type:
System.Web.UI.WebControls.WebParts::WebPart^
The control that provides data to consumer when the controls are connected.
- providerConnectionPoint
-
Type:
System.Web.UI.WebControls.WebParts::ProviderConnectionPoint^
A ConnectionPoint that enables provider to participate in a connection.
- consumer
-
Type:
System.Web.UI.WebControls.WebParts::WebPart^
The control that receives data from provider when the controls are connected.
- consumerConnectionPoint
-
Type:
System.Web.UI.WebControls.WebParts::ConsumerConnectionPoint^
A ConnectionPoint that acts as a callback method so that consumer can participate in a connection.
Return Value
Type: System::BooleanA Boolean value that indicates whether provider and consumer can be connected.
This method is used to connect provider and consumer when both controls have compatible connection point types, so that a WebPartTransformer object is not needed. You might want to use this method to verify that two controls can be connected before calling ConnectWebParts to create a programmatic connection.
This overload uses the same implementation as the CanConnectWebParts(WebPart^, ProviderConnectionPoint^, WebPart^, ConsumerConnectionPoint^, WebPartTransformer^) method overload, with the only exception being that this overload does not require a transformer.
The following code example demonstrates how to use this method.
The code example has four parts:
A user control that enables you to change display modes on a Web Parts page.
A Web page that contains two custom WebPart controls that can be connected, an <asp:webpartmanager> element, and some event-handling code that creates a connection using the CanConnectWebParts method.
A source code file that contains two custom WebPart controls, and a custom interface.
An explanation of how the example works in a browser.
The first part of the code example is the user control for changing display modes. You can obtain the source code for the user control from the Example section of the WebPartManager class overview. For more information about display modes and how the user control works, see Walkthrough: Changing Display Modes on a Web Parts Page.
The declarative markup for the Web page contains Register directives for both the user control and the custom controls. There is an <asp:webpartmanager> element, an <asp:webpartzone> element to contain the custom controls, and an <asp:connectionszone> element. Notice that in the Page_Load method, the code checks whether the connection can be made and, if so, defines a provider, a consumer, and their respective connection points, and then adds a new connection to the set of static connections referenced by the StaticConnections property.
The third part of the example is the source code for the controls. It contains an interface and two custom WebPart controls, one acting as a provider, and the other as a consumer. Because they have compatible connection points (both of them recognize the IZipCode interface), a transformer is not needed to make the connection. For the code example to run, you must compile this source code. You can compile it explicitly and put the resulting assembly in your Web site's Bin folder or the global assembly cache. Alternatively, you can put the source code in your site's App_Code folder, where it will be dynamically compiled at run time. For a walkthrough that demonstrates how to compile, see Walkthrough: Developing and Using a Custom Web Server Control.
After you have loaded the Web page in a browser, click the Display Mode drop-down list control and select Connect to switch the page to connect mode. Connect mode uses the <asp:connectionszone> element to enable you to create connections between controls. In connect mode, click the downward arrow in the title bar of the ZIP Code control to activate its verbs menu, and then click Connect. After the connection user interface (UI) appears, notice that a connection has already been created by the code contained in the Page_Load method.
Available since 2.0