concept JavaScript in category sharePoint

appears as: JavaScript, JavaScript, The JavaScript
SharePoint 2010 Web Parts in Action

This is an excerpt from Manning's book SharePoint 2010 Web Parts in Action.

The main reason for using this Web Part implementation is that it has some exclusive features when working with Web Part connections, features that the ASP.NET Web Part doesn’t provide. The SharePoint Web Part can be connected to other Web Parts that either reside on other pages within the site or that don’t exist in any zone (in other words, static Web Parts). The ASP.NET Web Part only accepts connections between Web Parts placed in zones and on the same page. The SharePoint Web Part can also handle client-side connections using the Web Part Page Services Component (WPSC). This is no longer such a big deal because the new SharePoint 2010 Client Object Model, in combination with JavaScript, can be used to create a similar experience. Another reason for using the SharePoint Web Part is that it has a built-in feature for caching content.

In the custom JavaScript file, you need a function (see listing 10.3) to invoke the timer that will refresh the feed at regular intervals. You’ll create the JavaScript functions using JavaScript object literal notation—that is, you’ll create a namespace that holds all the functions and variables. This best practice avoids function naming collisions and saves you a great deal of troubleshooting. In this case, you’ll add an object literal to the window object only if it isn’t already defined.

Listing 10.3. JavaScript with jQuery timer plug-in that updates the Web Part partially

Before continuing, I want to warn you about building Ribbon extensions and especially contextual ones. Creating a Ribbon extension requires a lot of XML coding. If you’ve worked with previous versions of SharePoint, you’re familiar with this declarative approach. Visual Studio 2010 doesn’t offer good support for building Ribbon extensions. In addition to writing XML code, you must be able to write quite a lot of JavaScript code. The JavaScript and XML code are sensitive to which ids you assign to items, so you need to build your Ribbon extensions carefully. Hopefully this chapter will make all this easier for you.

10.1. Using Ajax and JavaScript in Web Parts

JavaScript and XML have made the web more accessible and interactive. The combination of these two, called Ajax, is what most people mean when they refer to the technology used to make websites dynamic. Ajax techniques allow you to retrieve information in an asynchronous way. The web page is displayed with placeholders that are asynchronously filled with content, which means the entire page doesn’t have to reload for every single change. The same goes for Web Parts. A Web Part might initially contain a placeholder; after the page is rendered, it can asynchronously request information that fills that placeholder. In this way, you can change a page by updating just a Web Part. This is called a partial update.

SharePoint 2007: Developer’s Guide to Business Data Catalog

This is an excerpt from Manning's book SharePoint 2007: Developer’s Guide to Business Data Catalog.

In order to get the web part to refresh by itself, we could write a web service and use JavaScript to fire the web service similar to Ajax. But my friend Todd Bleeker introduced me to the Callback method, which is a way to embed JavaScript into your code to mimic Ajax. There’s no need to write a web service with this method. It seems to work well! First, let’s make sure we can continue to test our code by getting around the code access security issue.

sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest