Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [455]

By Root 5479 0
the PageRequestManager object fires the pageLoading client event. The event is raised after the server response is received but before any content on the page is updated. You can use this event to provide a custom transition effect for updated content or to run any clean-up code that prepares the panels for the next update. The event data is packed in an instance of the class PageLoadingEventArgs. The class has three properties: panelsUpdating, panelsDeleting, and dataItems. The first two are arrays and list the updatable panels to be updated and deleted, respectively.

The pageLoaded event is raised after all content on the page is refreshed. You can use this event to provide a custom transition effect for updated content, such as flashing or highlighting updated contents. The event data is packed in the class PageLoadedEventArgs, which has three properties: panelsUpdated, panelsDeleted, and dataItems. The first two are arrays and list the updatable panels that were just updated and deleted, respectively.

The endRequest event signals the termination of the asynchronous request. You receive this event regardless of the success or failure of the asynchronous postback.

Disabling Visual Elements During Updates


If you want to prevent users from generating more input while a partial page update is being processed, you can also consider disabling the user interface—all or in part. To do so, you write handlers for beginRequest and endRequest events:

You typically use the beginRequest event to modify the user interface as appropriate and notify the user that the postback is being processed:

// Globals

var currentPostBackElem;

function OnBeginRequest(sender, args)

{

// Get the reference to the button click (i.e., btnStartTask)

currentPostBackElem = args.get_postBackElement();

if (typeof(currentPostBackElem) === "undefined")

return;

if (currentPostBackElem.id.toLowerCase() === "btnStartTask")

{

// Disable the button

$get("btnStartTask").disabled = true;

}

}

The beginRequest handler receives event data through the BeginRequestEventArgs data structure—the args formal parameter. The class features only two properties: request and postBackElement. The properties have the same characteristics of analogous properties on the aforementioned InitializeRequestEventArgs class.

In the preceding code snippet, I disable the clicked button to prevent users from repeatedly clicking the same button.

At the end of the request, any temporary modification to the user interface must be removed. So animations must be stopped, altered styles must be restored, and disabled controls must be re-enabled. The ideal place for all these operations is the endRequest event. The event passes an EndRequestEventArgs object to handlers. The class has a few properties, as described in Table 20-8.

Table 20-8. Properties of the EndRequestEventArgs Control

Property

Description

dataItems

Returns the client-side dictionary packed with server-defined data items for the page or the control that handles this event. (More on registering data items later.)

Error

Returns an object of type Error that describes the error (if any) that occurred on the server during the request.

errorHandled

Gets and sets a Boolean value that indicates whether the error has been completely handled by user code. If this property is set to true in the event handler, no default error handling will be executed by the ASP.NET AJAX client library.

Response

Returns an object of type Sys.Net.WebRequestExecutor that represents the executor of the current request.

As you can see, when the endRequest event occurs there’s no information available about the client element that fired the postback. If you need to restore some user interface settings from inside the endRequest event handler, you might need a global variable to track which element

Return Main Page Previous Page Next Page

®Online Book Reader