Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Finally I used another approach to reach my goal. In the OnLoad event of the provider webpart, I check if my page is in edit/new mode, and then check if the page contains the consumer webpart (via the webpartmanager) and if they are not already connected. If this is the case, I connect them.</p> <p>The code to connect permanently the webparts:</p> <pre><code>private void SetUpConnections() { SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite siteContext = new SPSite(SPContext.Current.Site.ID)) using (SPWeb webContext = siteContext.OpenWeb(siteContext.ServerRelativeUrl)) using (SPLimitedWebPartManager spManager = webContext.GetFile(SPContext.Current.File.Url).GetLimitedWebPartManager(PersonalizationScope.Shared)) { foreach (Microsoft.SharePoint.WebPartPages.WebPart consumer in spManager.WebParts) { if (consumer is MyConsumerWebPart) { bool alreadyConnected = false; Microsoft.SharePoint.WebPartPages.WebPart provider = spManager.WebParts[this.ID] as Microsoft.SharePoint.WebPartPages.WebPart; foreach (SPWebPartConnection connection in spManager.SPWebPartConnections) { if (connection.Provider == provider &amp;&amp; connection.Consumer == consumer) { alreadyConnected = true; break; } } if (!alreadyConnected) { // Connects webparts permanently (but the page would need a reload to display the connection) ProviderConnectionPoint providerConnectionPoint = spManager.GetProviderConnectionPoints(provider)["MyConnectionProviderInterfaceId"]; ConsumerConnectionPoint consumerConnectionPoint = spManager.GetConsumerConnectionPoints(consumer)["MyConnectionConsumerInterfaceId"]; spManager.SPConnectWebParts(provider, providerConnectionPoint, consumer, consumerConnectionPoint); // Connects webparts locally (for current edit mode) SPWebPartManager currentSPManager = WebPartManager.GetCurrentWebPartManager(this.Page) as SPWebPartManager; System.Web.UI.WebControls.WebParts.WebPart currentProvider = this; System.Web.UI.WebControls.WebParts.WebPart currentConsumer = currentSPManager.WebParts[consumer.ID]; ProviderConnectionPoint currentProviderConnectionPoint = currentSPManager.GetProviderConnectionPoints(currentProvider)["SearchBarProvider"]; ConsumerConnectionPoint currentConsumerConnectionPoint = currentSPManager.GetConsumerConnectionPoints(currentConsumer)["SearchBarConsumer"]; currentSPManager.SPConnectWebParts(currentProvider, currentProviderConnectionPoint, currentConsumer, currentConsumerConnectionPoint); } } } } }); } </code></pre> <p>The code to check if the page is in new/edit mode:</p> <pre><code>if (SPContext.Current.FormContext.FormMode == SPControlMode.New || SPContext.Current.FormContext.FormMode == SPControlMode.Edit) { this.SetUpConnections(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload