A Web Parts connection consists of two server controls residing in a WebPartZoneBase zone and sharing data by means of an interface instance passed from one control to the other. The control that serves the interface instance is called the provider, and the control that receives the interface instance and processes or displays the data is called the consumer. For details on connections, see the WebPartConnection class and Web Parts Connections Overview.

The consumer control in a connection can be a WebPart control or any type of server or user control, but it must have a method designated as a callback method. The callback method is invoked during the connection process, and its purpose is to receive from the provider an interface instance that contains data. To designate the method that serves as the callback method in a consumer, you must add a ConnectionConsumerAttribute metadata element to the method (the element is based on the ConnectionConsumerAttribute class).

In addition to designating the callback method in a consumer, the ConnectionConsumerAttribute object also enables you to specify certain details about a consumer's connection point. A consumer connection point is an instance of the ConsumerConnectionPoint class that encapsulates all the details about a consumer needed to establish a connection, including the consumer's control type, whether it can connect to multiple providers at the same time, what type of interface the consumer can receive from a provider, details about the callback method, and a display name that represents the consumer connection point in the user interface (UI). Every Web Parts connection includes a consumer connection point that is associated with the consumer control.

When you add the ConnectionConsumerAttribute metadata element to the callback method in a consumer, you can also use it to specify the following details about the consumer connection point: a display name for the connection point (for details, see the DisplayName property), whether the consumer can connect to multiple providers at the same time (for details, see the AllowsMultipleConnections property), an ID for the connection point (for details, see the ID property), and the type of the connection point that the consumer uses (for details, see the ConnectionPointType property). The four overloads of the constructor for the ConnectionConsumerAttribute class each have parameters that allow you to specify values for one or more of these connection point properties when a new instance of the class is created. Most of the properties for a consumer connection point can also be set programmatically; setting them using the ConnectionConsumerAttribute element is optional.

Note

When you add the ConnectionConsumerAttribute metadata element to a callback method in a consumer, the only required parameter that you must always specify is the displayName parameter (for details, see the ConnectionConsumerAttribute(String) constructor overload). The value of this parameter is assigned to the DisplayName property, and when a user opens the connection UI (created by the ConnectionsZone control), the display name represents the consumer connection point in the UI. If you designate multiple callback methods in a consumer control, you will have multiple possible connection points to choose from, and when you add the ConnectionConsumerAttribute metadata element to each callback method, you should also specify a value for the id parameter, so that each consumer connection point has a known, unique identifier.

The following code example demonstrates using the ConnectionConsumerAttribute class, by showing how to declare the ConnectionConsumerAttribute metadata element on a callback method in a consumer control. Note that the simplest overload of the constructor is used; only the displayName parameter value is supplied.

The following code examples demonstrate how to create a basic, static connection between two Web Parts controls using the WebPartConnection class. The provider and consumer code files should be put into the App_Code folder under the application folder that contains the .aspx page.