Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have created two webparts via Visual Studio. After taking the connections option in the SharePoint UI, I'm able to connect between webparts. Is there any way to set the connections completely in the visual studio code itself ?

share|improve this question
add comment

2 Answers 2

up vote 6 down vote accepted

In SharePoint, a web part can be 'connected' to another web part to provide some information at run-time. The Provider web part pushes out the contracted information and the Consumer web part is set up to receive and consume the shared information.

This functionality lends to setting up a combination of simple web parts which may have been developed separately, into a functional and re-usable solution.

Basics

(1) Interface

a. This custom interface will define the data to be shared from the Provider to the Consumer web part.

(2) Provider web part

a. Inherits from Microsoft.SharePoint.WebPartPages.WebPart

b. Implements a data interface - this interface is a definition of the data that will be shared from the Provider web part to the Consumer web part.

c. Provide mechanisms for user selection of the interfacing data

d. Provide a ConnectionProvider method which will expose the interfacing data to the Consumer web part.

(3) Consumer web part

a. ConnectionConsumer method which will receive the interfacing data

b. 'Consume' the interfacing data and provide enriching details to the user.

you can also do it using SPLimitedWebPartManager to connect the Web parts with ASP.NET style interfaces.

Follow the steps in the below URL to do your requirement,

  1. Connecting Custom Web Parts in SharePoint

  2. Connected Web Parts in SharePoint 2010 - an Architectural Framework

  3. Walkthrough: Creating Connectable Web Parts in SharePoint

  4. Connectable Web Parts in SharePoint 2010

  5. Complete Code of SharePoint 2007 (MOSS/WSS) Connected Web Parts using IWebPartField Interface

I haven't tried with Visual Studio, but the following approach will be helpful to do your requirement,

We can create a static Web Parts connection between two server controls by declaring the connection in page persistence format. A static connection becomes a permanent object on a Web page, like a declared control. All users can see a static connection (because it is a shared object), and they can never delete the connection object, although they can disconnect it if provided with the user interface (UI) options for doing so. Static connections are a good option when you want a connection that is always available to all users, and you do not want users to have the option of deleting it from the page.

Declare a Static Connection between Two Web Parts Controls

share|improve this answer
    
Thanks for the detailed reply. I'll try with this. :) –  Anish V Dec 11 '13 at 13:27
    
I have connected the webparts and its working fine. But, sometimes when I take the page, it get redirected to the home page. In ULS logs, not much info was there... See this msg.. Orphaning WebPart with id g_76cd0982_9a0c_418c_a50b_0154a1b99981 on Page esiadsspdplot2:4444/Pages/home.aspx?ReturnUrl=/Pages/…. Any idea about this error ? –  Anish V Dec 12 '13 at 13:24
add comment

Yes, You can connect your webparts programmatically, below are good links to achieve your goal:

http://ojasmaru.blogspot.in/2012/07/sharepoint-2010-programmatically.html

http://code.msdn.microsoft.com/sharepoint/SharePoint-2010-Developing-2ed84e77/view/SourceCode#content

share|improve this answer
    
Please do not only provide links as answer, extend your answer with the important bits from your links. If the links break, your answer will not be very helpful as it looks now :) –  Robert Lindgren Dec 11 '13 at 6:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.