Thursday, April 15, 2010

Ajax and SharePoint web part loading

One of the marvels of modern web technology is the ability to communicate with the web server asynchronously using partial postbacks. This ensures that the web application behaves more like a desktop application and there are no full page refreshes required to reload the information that is hosted on a web page. Since 2005 Ajax has been used as a mainstream web development technique and has support from most software vendors including Microsoft.

Having the ability to reload only the areas of a web page that are required, improves the user experience and eliminates the page flickers that plagued early web applications. The benefits of using Ajax are really only seen on the client side, with very little to no changes in the web server infrastructure. The web request method still relies on a single call to request the web page content and does not support simultaneous requests.

If your web part relies on server requests to provide data to the UI, you may consider queueing the requests to ensure that the web parts each get a turn to request their information. The benefit of this approach is that the web parts will render their content and issue a postback once the entire page has been rendered.

The following script will enqueue post back requests and issue them in sequence for each web part.

Tuesday, April 13, 2010

SharePoint and Ajax Postback issue

SharePoint Server is a great application platform that has rich out of the box functionality. Building custom solutions on SharePoint may require a little more research to ensure that you are able to implement modern UI capabilities. One of the issues we found recently is that SharePoint in its native configuration does not support simultaneous postbacks.

Our design goal was to build web parts that behaved independently and that would issue postbacks as each part was loaded. This would allow the web page UI to load while the data was being fetched in the background.

Once we had built our Asp.Net user controls we found that they did not work as expected in a SharePoint enviornment. This relates to the way that Sharepoint handles post backs and a fix that Microsoft implemented to cater for double byte url's. Luckily the fix is quite easy to implement, that is once you have identifed the reason why subsequent post backs were failing.

Adding the following two lines of javascript code at the top of the web page solved the problem.

_spOriginalFormAction = document.forms[0].action;
_spSuppressFormOnSubmitWrapper=true;