This documentation is archived and is not being maintained.

WebPartManager.StaticConnections Property

Gets a reference to the collection of all WebPartConnection objects on a Web page that are defined as static connections.

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

public WebPartConnectionCollection StaticConnections { get; }

Property Value

Type: System.Web.UI.WebControls.WebParts.WebPartConnectionCollection
A WebPartConnectionCollection that contains all the static connections on the page.

The StaticConnections property is used by the WebPartManager control to track and manage all static connections on a page. A static connection, in contrast with a dynamic connection, does not need to be added to a page every time the page is rendered.

The collection referenced by this property contains all the static connections that exist on the page, whether they are created programmatically or specified with an <asp:webpartconnection> element in the page's markup.

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

The code example has four parts:

  • A user control that enables you to change display modes on a Web Parts page.

  • A source code file that contains two custom WebPart controls and a custom interface.

  • A Web page that contains two custom WebPart controls that can be connected, and an <asp:webpartmanager> element.

  • An explanation of how the example works in a browser.

The following code contains only the Web page portion of the example. You will also need to obtain the first two parts of the example--the custom user control and the source code for the custom controls and interface--from the Example section of the WebPartManager class overview. That topic also explains your options for compiling the WebPart controls.

The third part of the code example is the Web page. The declarative markup for the page contains Register directives for both the user control and the custom controls. There is an <asp:webpartmanager> element, an <asp:webpartzone> element to contain the custom controls, and an <asp:connectionszone> element. Notice that in the Page_Load method, the code checks to see whether a connection already exists and, if not, defines a provider, a consumer, and their respective connection points, and then adds a new connection to the set of static connections referenced by the StaticConnections property.

<%@ Page Language="C#" %>
<%@ register TagPrefix="uc1" 
  Src="DisplayModeMenuCS.ascx" %>
<%@ register tagprefix="aspSample" 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

  protected void Page_Load(object sender, EventArgs e)

    // Define provider, consumer, and connection points.
    WebPart provider = mgr.WebParts["zip1"];
    ProviderConnectionPoint provConnPoint =
    WebPart consumer = mgr.WebParts["weather1"];
    ConsumerConnectionPoint consConnPoint =

    // Check whether the connection already exists.
    if (mgr.CanConnectWebParts(provider, provConnPoint,
      consumer, consConnPoint))
      // Create a new static connection.
      WebPartConnection conn = new WebPartConnection();
      conn.ID = "staticConn1";
      conn.ConsumerID = "weather1";
      conn.ConsumerConnectionPointID = "ZipCodeConsumer";
      conn.ProviderID = "zip1";
      conn.ProviderConnectionPointID = "ZipCodeProvider";


<html xmlns="" >
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
    <form id="form1" runat="server">
      <!-- Reference the WebPartManager control. -->
      <asp:WebPartManager ID="mgr" runat="server" />   
      <uc1:DisplayModeMenuCS ID="displaymode1" 
        runat="server" />
      <!-- Reference consumer and provider controls 
           in a zone. -->
      <asp:WebPartZone ID="WebPartZone1" runat="server">
          <aspSample:ZipCodeWebPart ID="zip1" 
            Title="Zip Code Control"/>
          <aspSample:WeatherWebPart ID="weather1" 
            Title="Weather Control" />
      <hr />
      <!-- Add a ConnectionsZone so users can connect 
           controls. -->
      <asp:ConnectionsZone ID="ConnectionsZone1" 
        runat="server" />

After you have loaded the Web page in a browser, click the Display Mode drop-down list control and select Connect to switch the page to connect mode. Connect mode uses the <asp:connectionszone> element to enable you to create connections between controls. In connect mode, click the downward arrow in the title bar of the ZIP Code control to activate its verbs menu, and then click Connect. After the connection user interface (UI) appears, notice that a connection has already been created by the code contained in the Page_Load method. If you return to this page in a later browser session, this static connection will already be established and will not need to be recreated each time the page loads.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.