08.01.2015 Views

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 13<br />

Ajax Scripts <strong>and</strong> Services<br />

As you saw in Chapter 12, <strong>ASP</strong>.<strong>NET</strong> <strong>AJAX</strong> has both server <strong>and</strong> client components. You<br />

saw how you use the ScriptManager to create a service reference so that a web service<br />

can be accessed directly from JavaScript.<br />

In this chapter, you will look at some of the server controls <strong>and</strong> their supporting<br />

classes in some more detail. In particular, you will look at the ScriptManager control <strong>and</strong><br />

how it can be used to link your server <strong>and</strong> client applications neatly. It enables <strong>ASP</strong>.<strong>NET</strong><br />

<strong>AJAX</strong> applications to work within the browser, along with its partner control, the Script-<br />

ManagerProxy. You’ll see how to deliver custom scripts to the browser, how to manage<br />

partial page rendering, <strong>and</strong> how to access web services directly from script.<br />

You’ll build on this to look at how Ajax applications can access <strong>ASP</strong>.<strong>NET</strong> services such<br />

as memberships <strong>and</strong> profiles, building out a role-based secured site in <strong>ASP</strong>.<strong>NET</strong> <strong>and</strong> then<br />

seeing how this can be accessed from JavaScript as well as <strong>ASP</strong>.<strong>NET</strong>.<br />

The ScriptManager Class<br />

The ScriptManager class is designed to manage the <strong>ASP</strong>.<strong>NET</strong> <strong>AJAX</strong> script libraries, all the<br />

script files that you use within your application, <strong>and</strong> proxy class generation for web services.<br />

In addition, it supports the UpdatePanel, UpdateProgress, <strong>and</strong> Timer controls to<br />

perform their partial page refreshing <strong>and</strong> timing functions. These controls will not work<br />

unless a ScriptManager is present. Finally, it offers the JavaScript classes that are necessary<br />

to access authentication <strong>and</strong> profiling services.<br />

Partial Page Rendering<br />

As you saw in the previous chapter, by storing page content <strong>and</strong> controls within Update-<br />

Panels, partial page updates become possible. This is managed by the ScriptManager<br />

component, which delivers scripts that interact with the page life cycle (you can see this<br />

in more depth in Chapter 3). The ScriptManager has an EnablePartialRendering property<br />

that allows you to override this. By default, it is set to true, meaning that partial rendering<br />

is automatically enabled, <strong>and</strong> all UpdatePanel controls will refresh upon postback (but<br />

309

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!