Spicing Up Web Parts

20
Spicing Up Web Parts Randy Williams SharePoint Hawaii User Group May 11, 2011

description

Spicing Up Web Parts. Randy Williams SharePoint Hawaii User Group May 11, 2011. About the Speaker. US-West Coast Manager for Synergy Based in San Diego, California Consultant/Trainer/Author SharePoint MVP Specialty in architecting s olutions Blog: www.synergyonline.com/randy - PowerPoint PPT Presentation

Transcript of Spicing Up Web Parts

Page 1: Spicing Up Web Parts

Spicing Up Web Parts

Randy WilliamsSharePoint Hawaii User GroupMay 11, 2011

Page 2: Spicing Up Web Parts

About the Speaker

• US-West Coast Manager for Synergy–Based in San Diego, California

• Consultant/Trainer/Author• SharePoint MVP• Specialty in architecting solutions• Blog: www.synergyonline.com/randy• Twitter: @tweetraw

Page 3: Spicing Up Web Parts

Agenda

• AJAX• Custom Web Services• Client Object Model• jQuery

Page 4: Spicing Up Web Parts

How AJAX Works

• AJAX consists of JavaScript, DHTML and XMLHTTP

• XMLHTTPRequest object–Acts as a web service client–Used instead of a full postback

• Web server processes request and sends back response to browser

• Browser receives the response and updates the page dynamically

Page 5: Spicing Up Web Parts

Using AJAX in SP2010

• No configuration changes needed–Built into web.config–Built into v4.master

• Two primary ways–Using UpdatePanel control (basic)–Calling web services (advanced)

Page 6: Spicing Up Web Parts

UpdatePanel

• Part of ASP.NET 3.5• Easiest way to add AJAX capability• Most server-side events run as partial postbacks

• For SharePoint, use conditional modeup.UpdateMode =

UpdatePanelUpdateMode.Conditional;• Simple, but limited

Page 7: Spicing Up Web Parts

USING UPDATE PANELDemo

Page 8: Spicing Up Web Parts

Calling Web Services

• Using AJAX, the browser can directly call into Web Services

• More powerful than UpdatePanel• JSON is used to encode messages• AJAX engine does most of the hard work• Depending on the method used, OOB Web Services will not work–Custom ones can be used

Page 9: Spicing Up Web Parts

Creating Custom Web Services

• Create new WCF Service App project• Write web service• Configure a web.config for web service–Dynamic bindings will not work with AJAX–enableWebScript endpoint behavior – allows it to be called from AJAX client

• Deploy within 14\ISAPI

Page 10: Spicing Up Web Parts

USING AJAX TO CALL CUSTOM WEB SERVICE

Demo

Page 11: Spicing Up Web Parts

Client Object Model

• Working with SharePoint from client applications–ECMAScript (JavaScript)–Silverlight– .NET Managed

• Easier than calling web services directly• Provides a subset of the functionality available in the server object model

• Designed to work with data within a site collection

Page 12: Spicing Up Web Parts

The ClientContext Object

• ClientContext is your handle to all other objects– Site, Web, List, Item, File

• Optimizes communication to server by batching requests

• Typical usage:–Define a query to retrieve or modify SharePoint objects– Pass the query to one of the ClientContext’s Load

methods–Use ClientContext to execute the query–Work with results returned

Page 13: Spicing Up Web Parts

CLIENT OM FROM SILVERLIGHT WEB PART

Demo

Page 14: Spicing Up Web Parts

Using jQuery

• Multi-purpose JavaScript library• With it, you will write less JavaScript • Cross-browser support• Create interactive and usable apps• No need to deploy assemblies• Works great in sandboxed web parts• Hundreds of jQuery plugins

Page 15: Spicing Up Web Parts

Where to Store these .js Libraries?

• Deploy as a module-type feature–Works in both farm and sandboxed WSP

• Copy manually to designed libraries–e.g. SiteAssets

• Shared or individual instances?• Best to not rename file–e.g. keep as jquery-1.5.1.js

Page 16: Spicing Up Web Parts

USING JQUERYDemo

Page 17: Spicing Up Web Parts

Using SPServices

• Two primary functions–Allows jQuery to easily call SharePoint OOB web services

–ListFormWebPart enhancements• Download from http://spservices.codeplex.com/

• Use when Client OM is insufficient

Page 18: Spicing Up Web Parts

USING JQUERY AND SPSERVICES

Demo

Page 19: Spicing Up Web Parts

QUESTIONS?

Page 20: Spicing Up Web Parts