Compartilhar via


WebPart.PartCommunicationConnect Method

NOTE: This API is now obsolete.

Used to notify a Web Part that it has been connected to another Web Part.

Namespace:  Microsoft.SharePoint.WebPartPages
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No

Syntax

'Declaration
<ObsoleteAttribute("Use ConnectionProvider or ConnectionConsumer attribute to create ConnectionPoint instead.")> _
Public Overridable Sub PartCommunicationConnect ( _
    interfaceName As String, _
    connectedPart As WebPart, _
    connectedInterfaceName As String, _
    runAt As ConnectionRunAt _
)
'Usage
Dim instance As WebPart
Dim interfaceName As String
Dim connectedPart As WebPart
Dim connectedInterfaceName As String
Dim runAt As ConnectionRunAt

instance.PartCommunicationConnect(interfaceName, _
    connectedPart, connectedInterfaceName, _
    runAt)
[ObsoleteAttribute("Use ConnectionProvider or ConnectionConsumer attribute to create ConnectionPoint instead.")]
public virtual void PartCommunicationConnect(
    string interfaceName,
    WebPart connectedPart,
    string connectedInterfaceName,
    ConnectionRunAt runAt
)

Parameters

  • interfaceName
    Type: System.String

    Specifies the name of the interface on this Web Part that is being connected.

  • connectedInterfaceName
    Type: System.String

    Specifies the name of the interface that is being connected to on the other Web Part.

Remarks

A Web Part that implements a connection interface should override the PartCommunicationConnect method. This method is called by the Web Part infrastructure to notify the Web Part that it is connected during the Microsoft ASP.NET System.Web.UI.Control.PreRender event. Relevant information is passed to the connecting Web Part such as the interface it is connected over, the Web Part it is being connected to, and where the part will be running, either client-side or server-side.

If the Web Part that is being connected to is on another page, connectedPart is a null reference (Nothing in Visual Basic).

Examples

The following code example shows an overridden PartCommunicationConnect method. This code example is part of a larger example provided for the ICellProvider interface.

Because this example uses the Microsoft.SharePoint.Utilities.SPEncode class, it requires a using directive (Imports in Visual Basic) for the Microsoft.SharePoint.Utilities namespace.

For an overview of the steps of creating a connectable Web Part, see Walkthrough: Creating Connectable Web Parts in SharePoint Foundation.

Public Overrides Sub PartCommunicationConnect( _
    interfaceName As String, _
    connectedPart As WebPart, _
    connectedInterfaceName As String, _
    runAt As ConnectionRunAt)

   ' Keep track of whether the Web Part is connected.
   If interfaceName = "MyCellProviderInterface_WPQ_" Then
      _connected = True
      _connectedWebPartTitle = SPEncode.HtmlEncode(connectedPart.Title)
    End If
End Sub
// Step #7: Override the PartCommunicationConnect() method.
// The PartCommunicationConnect method is called by the Web Part infrastructure to notify the Web Part that it
// is connected during the ASP.NET PreRender event. Relevant information is passed to the part such as 
// the interface it is connected over, the Web Part it is being conected to, and where the part will be running, 
// either client-side or server-side. 
// <param name="interfaceName">Friendly name of the interface that is being connected</param>
// <param name="connectedPart">Reference to the other Web Part that is being connected to</param>
// <param name="connectedInterfaceName">Friendly name of the interface on the other Web Part</param>
// <param name="runAt">Where the interface should execute</param>
public override void PartCommunicationConnect(
    string interfaceName,
    WebPart connectedPart,
    string connectedInterfaceName,
    ConnectionRunAt runAt)
{
    // Keep track of whether the Web Part is connected.
    if (interfaceName == "MyCellProviderInterface_WPQ_")
    {
        _connected = true;
        _connectedWebPartTitle = SPEncode.HtmlEncode(connectedPart.Title);
    }
}

See Also

Reference

WebPart Class

WebPart Members

Microsoft.SharePoint.WebPartPages Namespace