Home > SharePoint, web parts > Connecting web parts programmatically

Connecting web parts programmatically

We need SPLimitedWebPartManager to connect the Web parts with ASP.NET style interfaces. The steps for this are:

  1. Get the SPLimitedWebPartManager instance on the page;
  2. Get the provider and consumer Web parts need to be connected;
  3. Get the connection points for the provider and consumer Web parts;
  4. Connect them using SPConnectWebParts method. If necessary, certain transforming needs to be in place for compatible interfaces
SPWeb web = (SPWeb)properties.Feature.Parent;      
SPLimitedWebPartManager mgr = web.GetLimitedWebPartManager("default.aspx", PersonalizationScope.Shared);
System.Web.UI.WebControls.WebParts.WebPart provider= mgr.WebParts["Provider"];
System.Web.UI.WebControls.WebParts.WebPart consumer= mgr.WebParts["Consumer"];
ConsumerConnectionPoint addConsumerConnPoint = mgr.GetConsumerConnectionPoints(consumer)["AddressConsumer_ot"];
ProviderConnectionPoint addProviderConnPoint = mgr.GetProviderConnectionPoints(provider)["AddressProvider_ot"];
mgr.SPConnectWebParts(provider, addProviderConnPoint, consumer, addConsumerConnPoint);
Categories: SharePoint, web parts
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: