WebPartConnection::Consumer Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets a WebPart object that is acting as the consumer control in a connection.

Namespace:   System.Web.UI.WebControls.WebParts
Assembly:  System.Web (in System.Web.dll)

public:
[BrowsableAttribute(false)]
property WebPart^ Consumer {
	WebPart^ get();
}

Property Value

Type: System.Web.UI.WebControls.WebParts::WebPart^

A WebPart that represents the Web Parts control acting as the consumer in a connection.

Exception Condition
InvalidOperationException

The length of the ConsumerID property is zero.

Every Web Parts connection consists of two controls that share data. One control acts as the provider of data, and the other control acts as a consumer, receiving and processing the data from the provider. The Consumer property gets a reference to the WebPart control acting as a consumer in a connection relationship.

The following code example demonstrates the programmatic use of the Consumer property.

The code 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.

No code example is currently available or this language may not be supported.

The second part of the code example is the source code for the two WebPart controls that serve as the consumer and the provider for the connection, and an interface used for the connection points. 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.

No code example is currently available or this language may not be supported.

The third part of the code example is the code for the Web page that hosts the controls and demonstrates the use of the Consumer property. Near the top of the page are the Register directives for the user control and the custom controls. Because this example uses dynamic compilation, the Register directive for the source file does not need to reference an assembly name; it includes only an arbitrary tag prefix and the namespace of the controls. In the Button2_Click method, the code accesses the connection object through the WebPartManager control, and gets a reference to the consumer control.

No code example is currently available or this language may not be supported.

After you load the page in a browser, use the Display Mode drop-down list control to switch the page to connect mode. Click the verbs menu (represented by the downward arrow in the title bar) on one of the WebPart controls, and click the connect verb. Use the Connect WebPart Controls button, or the provided connection user interface (UI), to create a connection between the two controls. Click the Display Consumer Info button to run the code that demonstrates the Consumer property.

.NET Framework
Available since 2.0
Return to top
Show: