15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1222 ❘ ChaPTer 41 Asp.net feAtures<br />

AJAX Extensions<br />

ASP.<strong>NET</strong> AJAX functionality is contained in two assemblies that are installed in the GAC:<br />

➤<br />

➤<br />

System.Web.Extensions.dll — This assembly contains the ASP.<strong>NET</strong> AJAX functionality, including<br />

the AJAX Extensions <strong>and</strong> the AJAX Library JavaScript files, which are available through the<br />

ScriptManager component (which is described shortly).<br />

System.Web.Extensions.Design.dll — This assembly contains ASP.<strong>NET</strong> Designer components<br />

for the AJAX Extensions server controls. This is used by the ASP.<strong>NET</strong> Designer in Visual Studio or<br />

Visual web developer.<br />

Much of the AJAX Extensions component of ASP.<strong>NET</strong> AJAX is concerned with enabling partial-page<br />

postbacks <strong>and</strong> JSON serialization for Web services. This includes various HTTP h<strong>and</strong>ler components <strong>and</strong><br />

extensions to the existing ASP.<strong>NET</strong> Framework. All this functionality can be configured through the web.<br />

config file for a web site. There are also classes <strong>and</strong> attributes that you can use for additional configuration.<br />

However, most of this configuration is transparent, <strong>and</strong> you will rarely need to change the defaults.<br />

Your main interaction with AJAX Extensions will be using server controls to add Ajax functionality to your<br />

web applications. There are several of these, which you can use to enhance your applications in various<br />

ways. The following table shows a selection of the server-side components. You see these components in<br />

action later in this chapter.<br />

ConTrol<br />

ScriptManager<br />

UpdatePanel<br />

UpdateProgress<br />

desCriPTion<br />

This control is central to ASP.<strong>NET</strong> AJAX functionality <strong>and</strong> is required on every<br />

page that uses partial-page postbacks. Its main purpose is to manage clientside<br />

references to the AJAX Library JavaScript files, which are served from the<br />

ASP.<strong>NET</strong> AJAX assembly. The AJAX Library is used extensively by the AJAX<br />

Extensions server controls, which all generate their own client-side code.<br />

This control is also responsible for the configuration of Web services that you<br />

intend to access from client-side code. By supplying Web service information<br />

to the ScriptManager control, you can generate client-side <strong>and</strong> serverside<br />

classes to manage asynchronous communication with Web services<br />

transparently.<br />

You can also use the ScriptManager control to maintain references to your own<br />

JavaScript files.<br />

The UpdatePanel control is an extremely useful one <strong>and</strong> is perhaps the ASP.<br />

<strong>NET</strong> AJAX control that you will use most often. This control acts like a st<strong>and</strong>ard<br />

ASP.<strong>NET</strong> placeholder <strong>and</strong> can contain any other controls. More important, it<br />

also marks a section of a page as a region that can be updated independently of<br />

the rest of the page, in a partial-page postback.<br />

Any controls contained by an UpdatePanel control that cause a postback<br />

(a Button control, for example) will not cause full-page postbacks. Instead,<br />

they cause partial-page postbacks that will update only the contents of the<br />

UpdatePanel.<br />

In many situations, this control is all you need to implement Ajax functionality. For<br />

example, you can place a GridView control in an UpdatePanel control, <strong>and</strong> any<br />

pagination, sorting, <strong>and</strong> other postback functionality of the control will take place<br />

in a partial-page postback.<br />

This control enables you to provide feedback to users when a partial page<br />

postback is in progress. You can supply a template for this control that will be<br />

displayed when an UpdatePanel is updating. For example, you could use a<br />

floating control to display a message such as “Updating...” so that the<br />

user is aware that the application is busy. Note that partial-page postbacks do<br />

not interfere with the rest of a web page, which will remain responsive.<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!