15.02.2015 Views

C# 4 and .NET 4

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

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

What is ajax ❘ 1237<br />

The PagerequestManager <strong>and</strong> application objects<br />

Among the most useful classes that the AJAX Library provides are the PageRequestManager<br />

<strong>and</strong> Application classes. You will find PageRequestManager in the Sys.WebForms namespace <strong>and</strong><br />

Application in the Sys namespace. The important thing about these classes is that they expose several<br />

events that you can attach JavaScript event h<strong>and</strong>lers to. These events occur at particularly interesting points<br />

in the lifecycle of a page (for Application) or partial-page postback (for PageRequestManager) <strong>and</strong> enable<br />

you to perform operations at these critical times.<br />

The AJAX Library defines event h<strong>and</strong>lers in a similar way to event h<strong>and</strong>lers in the .<strong>NET</strong> Framework. Every<br />

event h<strong>and</strong>ler has a similar signature, with two parameters. The first parameter is a reference to the object<br />

that generated the event. The second parameter is an instance of the Sys.EventArgs class or an instance of<br />

a class that derives from this class. Many of the events exposed by PageRequestManager <strong>and</strong> Application<br />

include specialized event argument classes that you can use to determine more information about the event.<br />

The following table lists these events in the order they will occur in a page that is loaded, triggers a partialpage<br />

postback, <strong>and</strong> is then closed.<br />

eVenT<br />

Application.init<br />

Application.load<br />

PageRequestManager.initializeRequest<br />

PageRequestManager.beginRequest<br />

PageRequestManager.pageLoading<br />

desCriPTion<br />

This event is the first to occur in the lifecycle of a page. It<br />

is raised after all the JavaScript files have been loaded but<br />

before any objects in the application have been created.<br />

This event fires after the objects in the application<br />

have loaded <strong>and</strong> been initialized. You will often use an<br />

event h<strong>and</strong>ler attached to this event to perform actions<br />

when the page is first loaded. You can also provide an<br />

implementation for a function called pageLoad() on a<br />

page, which is automatically defined as an event h<strong>and</strong>ler<br />

for this event. It sends event arguments by using a Sys<br />

.ApplicationLoadEventArgs object, which includes the<br />

isPartialLoad property that you can use to determine if<br />

a partial-page postback has occurred. Access this property<br />

with the get_isPartialLoad() accessor.<br />

This event occurs before a partial-page postback, before<br />

the request object is created. You can use the Sys<br />

.WebForms.InitializeRequestEventArgs event<br />

argument properties to access the element that triggered<br />

the postback (postBackElement) <strong>and</strong> the underlying<br />

request object (request).<br />

This event occurs before a partial-page postback, after the<br />

request object is created. You can use the Sys.WebForms<br />

.BeginRequestEventArgs event argument properties<br />

to access the element that triggered the postback<br />

(postBackElement) <strong>and</strong> the underlying request object<br />

(request).<br />

This event is raised after a partial-page postback,<br />

before any subsequent processing occurs. This processing<br />

can include elements that will be deleted or<br />

updated, which you can reference through the Sys<br />

.WebForms.PageLoadingEventArgs object by using the<br />

panelsDeleting <strong>and</strong> panelsUpdating properties.<br />

continues<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!