RSS Feed Feed your read!

Bookmark and Share







Tag Cloud

ASP.NET Generic, Best Practices, Business Intelligence, Freeware Releases, InfoPath, Infrastructure, jQuery, Lunch & Learn Events, Project Server, Random, Reporting Services, Search, SharePoint Administration, SharePoint Business Analysis and Project Management, SharePoint Development, Silverlight, Social Networking, Speaking Events, White Paper Releases, Workflow Foundation,

Archives

June 2007 (3)
August 2007 (1)
November 2007 (2)
February 2008 (2)
April 2008 (5)
May 2008 (7)
June 2008 (8)
July 2008 (7)
August 2008 (3)
September 2008 (7)
October 2008 (1)
November 2008 (3)
December 2008 (3)
January 2009 (7)
February 2009 (5)
March 2009 (10)
April 2009 (2)
May 2009 (6)
June 2009 (3)
July 2009 (4)
August 2009 (6)
September 2009 (3)
October 2009 (9)
November 2009 (10)
December 2009 (1)
January 2010 (1)
February 2010 (3)
March 2010 (6)
April 2010 (2)
May 2010 (3)
June 2010 (4)
July 2010 (3)

Connected Web Part Mechanisms Compared 

Tags: SharePoint Development

Are you looking to connect two custom SharePoint web parts to each other? Did you know there is more than one way to accomplish this? From what I've seen and heard from the developers around me is that most only know of one way, and in this post I'd like to discuss and compare this commonly known way with 2 other ways that are less known…

 

Approach #1: SharePoint Web Part Infrastructure Connections

 

This first approach to connectable web parts is by far the most widely known in the SharePoint community. Essentially, you can tap into the SharePoint Web Part infrastructure's connection interfaces to pass and receive data from one web part to another. The setting up of the connection is done through the UI, simply upload the web part(s), edit, and connect:

 

 

MSDN Walkthrough: http://msdn.microsoft.com/en-us/library/ms469765.aspx

 

Strengths

 

  • By far the easiest approach to implement from an architecture understandability perspective
  • By far the least amount of lines of code required
  • End users can setup/remove the connections, allowing solutions to be built at run time.
  • ISVs can build generic data points that can interact over the common web part infrastructure with your proprietary web parts or out of box web part.

Weaknesses

 

  • Post-backs are necessary (no ajax or client side script)

 

 

Approach #2: Client Side SharePoint Web Part Infrastructure Connections

 

Similar to approach #1, but it supports a client side (javascript) connection without the need to post back to the server when actions occur. If extreme usability is important, going with this approach is worth looking at, but developer beware, it takes more than a "Hello World" to implement client side connections. Here's a good write-up though: http://www.synergyonline.com/blog/blog-moss/Lists/Posts/Post.aspx?ID=20

 

Strengths

 

  • No post backs
  • End users can setup/remove the connections, allowing solutions to be built at run time.
  • ISVs can build generic data points that can interact over the common web part infrastructure with your proprietary web parts or out of box web part.

Weaknesses

 

  • Complicated implementation for most developers
  • Not supported in System.Web namespace, must use Microsoft.SharePoint V2 namespace (supportability?)

 

 

Approach #3: Client Side Callbacks

 

Using client side callbacks to connect web parts is not a commonly known or understood method, yet it remains one of my favorite and most frequently used techniques. The basic premise behind the technique is the Consumer web part drops a javascript method onto the page that can callback to the server to execute .NET code. Then, any other web part on the page, even a content editor web part (CEWP), can call that method and pass a parameter into that method, and in essence "Provide" data and "Connect" the two web parts together. Actually, any HTML object on the page can "Provide" data, since it's just javascript we're dealing with. It doesn't even have to be a web part!

 

For example, the screen shot below shows a data grid, and when a row in the data grid is selected, the "Item Details" web part shows the full details for that row:

 

 

Essentially, all that happens is when a user clicks the row in the data grid, a javascript method is called which was put onto the page by the Item Details web part. That Item details web part, on the client side, calls back to the server and executes a stored procedure and returns the result of that call and updates a DIV with that result.

 

  1. 1 - Javascript method dropped on page by "Consumer" web part is called by the "Provider" web part or sundry html object. (in this case when the user clicks a row in the grid view)
  2. 2 - "Consumer" web part calls back to server
  3. 3 - Web server requests some data
  4. 4 - SQL box returns some data
  5. 5 - "Consumer" web part updates a div on the page with the result of the callback from the web server

 

What's great too about this method is it is all ajaxically performed, and in my example I load up a progress bar while the callback is executing:

 

 

Strengths

 

  • No post backs
  • AJAX made easy with NO server side dependencies besides.NET 2.0 (not even web.config settings needed!)
  • Any HTML object on the page can "Connect" to the web part. (think quick launch, top nav, CEWP, C# web part, etc.)

Weaknesses

 

  • Complicated implementation for most developers
  • Isn't apart of the connection "Infrastructure" – so ISV web parts won't know how to connect to your web parts.
  • End users most likely won't be setting up these connections at run time – these connections typically are built/designed at design time by developers.

 

Here's a good write up to help you get started with client side callbacks: http://www.beansoftware.com/asp.net-tutorials/client-side-callback.aspx

 

Phil's Recommendation When to use Which

 

If you are…

 

  • Going to need to allow your end users to setup the "Connections" in the browser:

    Approach #1 if you don't care about post backs, and Approach #2 if you do…


  • You want an AJAX user experience and your end users won't be configuring the connections themselves:

    Approach #3 (much easier than #2 to implement)

 

Cheers!

 

Phil

 
Posted by BENDER\pwicklund on 11-Sep-09
0  Comment  |  Trackback Url  | 0  Link to this post | Bookmark this post with:        
 
Failed to render control: Value does not fall within the expected range.

Comments

Bookmark and Share

Note: Facebook no longer sends notifications for comments, so it may be a number of days before I see your post. For urgent matters, click "Contact Me" on the top nav. More info: Click Here.