Client Side AJAX Applications in SharePoint 2010 – Part 1: Introduction
Guest Author: Lee Richardson
http://rapidapplicationdevelopment.blogspot.com/
From a developer’s perspective WCF Data Services is one of the most compelling new features of SharePoint 2010. Using this technology in conjunction with ASP.Net AJAX 4.0 Templating, SharePoint developers can quickly build rich, responsive, web 2.0 user interfaces. And unlike with Silverlight based solutions end users won’t need anything beyond a modern browser.
But best of all, solutions based on the approach outlined in this series won’t require customizing SharePoint at all. No custom web parts, no site definitions, no application pages necessary. Everything in this series will work with plain content editor web parts and (nearly) out of the box SharePoint (it will require installing WCF Data services, but it’s free and it’s from Microsoft).
First a word of warning: This series will contain no C# whatsoever (or VB for that matter). There will be no compilation, and none of the benefits it brings: no type checking, no syntax checking, no LINQ to objects, no LINQ to SharePoint. And the kicker: there will be mediocre IntelliSense support from Visual Studio.
Why Would You Do This to Yourself?!
There are two main reasons why this approach should still interest you. First, if you goal is to build pretty, responsive user interfaces without any third party dependencies (e.g. Silverlight) there is no alternative to writing JavaScript. You simply could not write a Google maps style interface with ASP.Net AJAX server controls. Second, because this approach works with (nearly) out of the box SharePoint, you can build applications in locked down corporate environments without any deployment concerns.
Perhaps you’re wondering what’s wrong with the currently available techniques and why learning a whole new framework is necessary. If you’re writing Web 2.0 applications today with SharePoint 2007 there are really only two approaches: ASP.Net AJAX server side controls, or manually coding JavaScript, probably with jQuery or other JavaScript Libraries like jPoint. If you take the ASP.Net AJAX approach you’ll undoubtedly be using an UpdatePanel to get partial page refreshes and then writing ASP.Net code like you always have. There are several problems with this approach:
- It’s slow
- It sends the entire ViewState with every asynchronous request (this can actually sneak up on you once you have a lot of production data as happened to me recently)
- Even without a ViewState the UpdatePanel transmits large amounts of HTML (rather than lightweight JSON data)
- It runs through the entire page lifecycle on updates, executing everything on the page even if it isn’t relevant to what you’re doing
- ASP.Net AJAX doesn’t have the simplicity of an ETag based HTTP caching like with a REST solution
- Finally SharePoint just doesn’t work well with UpdatePanel (I can’t tell you how many issues I’ve had with various controls not working out of the box)
And if you take the manual JavaScript rout you are faced with a number of different problems:
- You have to write a lot of plumbing code
- You have to write a service to return your data
- You have to pay particular attention to security and permissions since you’re exposing your API’s to the world
- You have to convert your data (ideally JSON) into HTML with either
- String concatenation
- Document.createElement statements, or
- Some less than ideal JQuery syntax
- Your UI code is not clearly separated from your data access code making your code hard to maintain
- Saving data back to the server involves even more plumbing code and permissions issues
Summary
SharePoint 2010 and WCF Data Services combined with ASP.Net AJAX 4.0 Templating provide a very nice solution for all of these problems. The next article in the series will detail more of WCF Data Service. Future articles in the series will build up a simple application for managing user stories as index cards on a virtual cork board with jQuery and more importantly ASP.Net AJAX 4.0 Templating.
Guest Author: Lee Richardson
http://rapidapplicationdevelopment.blogspot.com/
Lee Richardson is a Senior Software Engineer at Near Infinity Corporation, an enterprise software development and consulting services company based in Reston, Virginia. He is a Microsoft Certified Solution Developer (MCSD), a Project Management Professional (PMP), a Certified SCRUM master and has over ten years of experience consulting for the public and private sector. You can follow Lee on Twitter at @lprichar
- Client Side AJAX Applications in SharePoint 2010 – Part 1: Introduction
- Client Side AJAX Applications in SharePoint 2010 – Part 2: WCF Data Services
- Client Side AJAX Applications in SharePoint 2010 – Part 3: ASP.Net AJAX Templating 101
- Client Side AJAX Applications in SharePoint 2010 – Part 4: jQuery Integration and Persistence
- Client Side AJAX Applications in SharePoint 2010 – Part 5: Modal Dialogs
- Client Side AJAX Applications in SharePoint 2010 – Part 6: Master-Details
- Client Side AJAX Applications in SharePoint 2010 – Part 7: Live Bindings
Oh Wow! I can’t wait for future episodes! Especially interested in the Templating feature.
Great post Lee – sounds promising!
Well, UI can be separated by using ASP.Net MVC. Not as fast using clean JSON, but still, you can.