WebPart.EnsureInterfaces method
SharePoint 2013
NOTE: This API is now obsolete.
Provides notification for a connectable Web Part that it should ensure all its interfaces are registered using the RegisterInterface method.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
The following code example shows an overridden EnsureInterfaces method. This code example is part of a larger example provided for the ICellProvider interface.
For an overview of the steps of creating a connectable Web Part, see Creating a Connectable Web Part.
// Step #4: Override the EnsureInterfaces() method and call the RegisterInterface method. public override void EnsureInterfaces() { // If your Web Part is installed in the bin directory and the Code Access Security (CAS) setting doesn't // allow Web Part Connections, an exception will be thrown. To allow your Web Part to behave // well and continue working, a try/catch block should be used when attempting to register interfaces. // Web Part Connections will only work if the level attribute of the <trust> tag in the // web.config file is set to WSS_Minimal, WSS_Medium, or Full. By default a new SharePoint site // is installed with the trust level set to WSS_Minimal. try { // Register the ICellProvider Interface // <param name="interfaceName">Friendly name of the interface that is being implemented. // It must be unique on the client so the _WPQ_ token is used.</param> // <param name="interfaceType">Specifies which interface is being implemented.</param> // <param name="maxConnections">Defines how many times this interface can be connected.</param> // <param name="runAtOptions">Determines where the interface can run.</param> // <param name="interfaceObject">Reference to the object that is implementing this interface.</param> // <param name="interfaceClientReference">Name used to reference the interface on the client. // It must be unique on the client so the _WPQ_ token is used.</param> // <param name="menuLabel">Label for the interface which appears in the UI</param> // <param name="description">Description of the interface which appears in the UI</param> // <param name="allowCrossPageConnection">Specifies if the interface can connect to a Web Part // on a different page. This is an optional parameter with a default of false. Note that only some // server side interfaces are allowed to connect across pages by the Web Part infrastructure. // The ICellProvider interface is not allowed to connect across pages.</param> RegisterInterface("MyCellProviderInterface_WPQ_", //InterfaceName InterfaceTypes.ICellProvider, //InterfaceType WebPart.UnlimitedConnections, //MaxConnections ConnectionRunAt.Server, //RunAtOptions this, //InterfaceObject "CellProviderInterface_WPQ_", //InterfaceClientReference "Provide Cell To", //MenuLabel "Provides a single value to a cell consumer Web Part."); //Description } catch(SecurityException se) { _registrationErrorOccurred = true; } }