Serves as the base class for defining connection point objects that enable the consumer control and the provider control in a Web Parts connection to share data.
Assembly: System.Web (in System.Web.dll)
Thetype exposes the following members.
|AllowsMultipleConnections||Gets a value that indicates whether a connection point supports multiple simultaneous connections.|
|ControlType||Gets the Type of the server control with which a connection point is associated.|
|DisplayName||Gets a string that serves as a friendly display name to represent a connection point in the user interface (UI).|
|ID||Gets a string that contains the identifier for a connection point.|
|InterfaceType||Gets the type of the interface used by a connection point.|
|Equals(Object)||Determines whether the specified object is equal to the current object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|GetEnabled||Returns a value that indicates whether a connection point can participate in connections.|
|GetHashCode||Serves as the default hash function. (Inherited from Object.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
Every Web Parts connection consists of two server controls sharing data: one control is the consumer, the other is the provider. For a discussion of the essential components of a Web Parts connection, and the connection object itself, see the WebPartConnection class overview. Every Web Parts connection requires connection points. The provider and the consumer control must each have at least one defined object (each of them can optionally have multiple connection points) that contains the details for how a control can connect to another control and the type of data it can share. In an actual connection, the provider has its own type of connection point object (derived from the base class), a ProviderConnectionPoint instance, and the consumer has its own object, a ConsumerConnectionPoint instance.
To create a provider connection point, developers must add a callback method to the provider that will return an implemented interface instance to a consumer. They must mark the callback method in the source code with a ConnectionProvider code attribute (see the ConnectionProviderAttribute class). Similarly, to create a consumer connection point, developers must add a method to the consumer that receives an interface instance, and they must mark that method with a ConnectionConsumer attribute (see the ConnectionConsumerAttribute class).
When developers create connections on a Web page, they can be created as static or dynamic connections. Static connections are declared in the markup of a Web page. When a static connection is declared, developers can designate which connection points are used for both the consumer and provider by assigning values to the ProviderConnectionPointID and ConsumerConnectionPointID attributes within the <asp:webpartconnection> element tag. This approach is especially useful if there are multiple connection points defined within the consumer and provider controls, because it enables the static connection to identify which connection points to use for the connection.
Dynamic connections are created programmatically, either by a developer's code or by users through the user interface (UI) provided by the ConnectionsZone control. To create a connection in code, developers must get an instance of a WebPartConnection object by calling the ConnectWebParts method on the WebPartManager control. Before they can call this method, developers must have references to the consumer and provider server controls and their respective connection point objects. To get references to the connection points for a provider and a consumer control, developers first call the GetProviderConnectionPoints and GetConsumerConnectionPoints methods on the WebPartManager control. These methods return the appropriate connection point objects, which in turn can be passed to the method for creating a connection.
When the provider's and the consumer's connection point objects both work with the same type of interface, they are compatible and can form a direct connection to share data. If they do not work with the same interface type, a WebPartTransformer object must be used to translate the interface instance from the provider into a type that the consumer can work with.
The abstract class provides the base details of connection points that are shared by both consumer and provider controls. Several properties contain these details. The AllowsMultipleConnections property indicates whether a connection point can participate in more than one connection at a time. By default, provider connection points can participate in multiple connections, and consumer connection points cannot. The ControlType property indicates the type of the server control associated with a connection point. Note that not only WebPart controls can form connections; any server control, whether an ASP.NET control, a custom control, or a user control, can be enabled to participate in connections if placed in a WebPartZoneBase zone. The DisplayName property provides a friendly name for the connection point that can be displayed in the UI to assist users who are creating connections. The ID property serves as a string identifier for the connection point object itself. The InterfaceType property indicates what type of interface instance the connection point understands. Whether a given connection point provides or consumes an instance of that interface is determined by whether it is a ProviderConnectionPoint or a ConsumerConnectionPoint object.
The class has one method. The GetEnabled method returns a Boolean value indicating whether a connection point is currently able to participate in connections.
The class also has one public field, DefaultID. This field contains a value used to identify the default connection point in a connection.
The attributes for specifying connection point methods have only one required parameter, displayName, so it is possible to create the default connection point attribute without specifying an ID. In such cases, the DefaultID field supplies a base value to use.
The following code example demonstrates the creation of a Web Parts connection that includes the required objects. Because the class is an abstract base class, instances of its child classes--ProviderConnectionPoint and ConsumerConnectionPoint--are the actual objects used to form a connection.
The example has four parts:
A user control that enables you to change the Web Parts display mode on a page.
Source code for an interface and two WebPart controls acting as the provider and the consumer for a connection.
A Web page to host all the controls and run the code example.
An explanation of how to run the example page.
The first part of this code example is the user control that enables users to change display modes on a Web page. Save the following source code to an .ascx file, giving it the file name that is assigned to the Src attribute of the Register directive for this user control, which is near the top of the hosting Web page. For details about display modes and a description of the source code in this control, see Walkthrough: Changing Display Modes on a Web Parts Page.
The second part of the code example is the source code for the interface and controls. The source file contains a simple interface named IZipCode. There is also a WebPart class named ZipCodeWebPart that implements the interface and acts as the provider control. Its ProvideIZipCode method is the callback method that implements the interface's only member. The method simply returns an instance of the interface. Note that the method is marked with a ConnectionProvider attribute in its metadata. This is the mechanism for identifying the method as the callback method for the provider's connection point. The other WebPart class is named WeatherWebPart, and it acts as the consumer for the connection. This class has a method named GetZipCode that gets an instance of the IZipCode interface from the provider control. Note that this method is marked as the consumer's connection point method with a ConnectionConsumer attribute in its metadata. This is the mechanism for identifying the connection point method in the consumer control.
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. This code example uses dynamic compilation. For a walkthrough that demonstrates how to compile, see Walkthrough: Developing and Using a Custom Web Server Control.
The third part of the code example is the Web page. Near the top are Register directives to register the custom controls that form the connection, and the user control that enables users to change display modes on the page. The connection itself is created declaratively within the <staticconnections> element on the page. You can also create the connection programmatically; the code for doing that is contained in the Button1_Click method. Whether the connection is created declaratively or programmatically, connection points must always be specified for both the provider and the consumer. The Button2_Click method accesses the objects for both the provider and the consumer, and writes some of their property values to a label in the page.
After you load the page in a browser, click the Connection Point Details button. Information about the provider and consumer connection points established in the declarative connection appears. Next, use the Display Mode drop-down control to switch the page into connect mode. On the verbs menu of one of the WebPart controls (represented by a downward arrow in the title bar), click the connect verb. The connection UI appears, created automatically by the <asp:connectionszone> control declared in the page. Click the Disconnect button to terminate the existing connection. Use the Display Mode control to return the page to browse mode. Next, click the Dynamic Connection button to create a connection programmatically. Click the Connection Point Details button again, to indicate details about the two connection point objects.