WebPartConnection::ID Property

 

Gets or sets the ID of a WebPartConnection object.

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

public:
property String^ ID {
	String^ get();
	void set(String^ value);
}

Property Value

Type: System::String^

A string that contains the ID of a WebPartConnection.

Every WebPartConnection object has a unique value assigned to its ID property. This is to ensure that there is a way to distinguish between multiple connections.

If you create a static connection by declaring an <asp:webpartconnection> element in a Web page, and you do not assign a value to the ID attribute for the connection, an exception is thrown when the WebPartManager control attempts to activate the connection.

When the WebPartManager control creates a new dynamic connection, it calls the CreateDynamicConnectionID method to generate a unique ID for the connection.

The following code example shows the declarative and programmatic use of the ID 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 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 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 ID 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. Here, the ID property is not required, because the connection is dynamic, and the WebPartManager control assigns an ID to the connection. In the Button2_Click method, the code accesses the value of the ID 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 Connection Details button to run the code that accesses the ID property value.

.NET Framework
Available since 2.0
Return to top
Show: