WebPartConnection.ConsumerID Property

Gets or sets the property value on a connection that references the ID of the WebPart control acting as a consumer for that connection.

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

public:
property String^ ConsumerID {
	String^ get ();
	void set (String^ value);
}
/** @property */
public String get_ConsumerID ()

/** @property */
public void set_ConsumerID (String value)

public function get ConsumerID () : String

public function set ConsumerID (value : String)

Not applicable.

Property Value

A string that contains the ID of the control acting as a consumer in a connection.

The ConsumerID property value is required when you create a connection between WebPart controls. If a value is not assigned to the property, an exception is thrown when the WebPartManager control attempts to activate the connection.

The following code example shows the declarative and programmatic use of the ConsumerID property.

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.

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 interface, and the consumer and provider controls. 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 Server Control.

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

The third part of the code example is the Web page. Note that a connection is declared in the page markup, using the <StaticConnections> and <asp:WebPartsConnection> elements. The connection declaration includes the required ConsumerID attribute. A second method for creating the connection appears in the Button1_Click method, where the code creates a new connection, using the connection point defined in the consumer control. Then, in the Button2_Click method, the code accesses the value of the ConsumerID property and displays it in a label.

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

After you load the page in a browser, a connection already exists because of the static connection declared in the page. Enter some text in the provider control, and note that it is displayed in the consumer due to the connection. Next, disconnect the controls. Using the Display Mode drop-down list control, 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. Click the Disconnect button. Use the Connect WebPart Controls button to recreate a connection between the two controls. Click the Consumer Details button to run the code that accesses the ConsumerID property value.

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.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show: