Skip to main content

70-562 AJAX

Compared to a desktop application, ASP.Net web applications are too dependent on the web server to create and build pages, added to network overhead, and a waste to re-generate a page for a small change, and it causes the page to flash. Client side scripting and AJAX allows the browser to work more.

The client use can become frustrated by too many postbacks that can ruin the web experience for the user.
AJAX also frees the server of having to regenerate pages.

AJAX can do async calls to update portions of the page. The server doesnt have the overhead, and resulting delay of creating a complex page from scratch.

With the arrival of AJAX, th etradition full-page processing can sometimes be replaced by AJAX partial-page processing. The intial full page comes from the server then can use either full or partial-page processing.

The way the server and browser processes an AJAX request is different than a tradtionnal HTTP Post.

AJAX uses a Javascript, and a client side ASP.Net AJAX library to make a request to the server, it bypasses the normal page processing.

The AJAX request is handled through a XMLHTTPResquest object introduced in IE5.

This is done async and the data is processed whenever it arrives, but leaves the browser responsive in the meantime.

The main motivation of asp.net was to make it easy and rich as desktop development.

Microsft's implement AJAX consists of two pieces, 1) Server-side AJAX 2)Client-side AJAX. Each of these two pieces handle entirely different senarios, and are based on 2 entirely different views of how to make pages more responsive to the user.

You can use both of those peices on you personal pages, you can mix and match and you can even include full page refreshes if appropriate for this type of applications.

SERVER-SIDE AJAX: fits nicely in overall ASP.Net page processing model because it reliase on teh server controls, it can be used as drag and drop from the designer mode.
ASP.Net 3.5 ships with 5 AJAX Server Controls, that you can find in the toolbox, the ScriptManager and UpdatePanel are the most used because they are mandatory for both client and server side AJAX.


ScriptManager doesnt have a user interface, and required for both server and client side ajax, and lets you configure the JavaScript that is required to implement AJAX for that particular page.
The PostBack events of any controls placed in the UpdatePanel container control,   will cause an AJAX request instead of full page PostBack depending on how you configured that update panel.

For server-side AJAX processing, most of the processing occurs on the server. The broswer only sets up the call, and responds to the result and that's it. Server side Ajax will fell like developping full page postbacks. You will probably spend most of the time in source view rather than design view since not much is implemented in design view.

CLIENT-SIDE AJAX: much closer to the original concept of AJAX.
This version of AJAX doesn't have a concept of page or page fragment updating. Instead your making a pure AJAX request and your getting raw data back and you're going to have client side scripting code in order to udate the page as appropriate for that response.

Microsoft provided the Microsoft AJAX client Library, makes JavaScript look like a .Net lanaguage with support along with some robust framework supoprt.

The AJAX client lirbary is implemented as a single JavaScript file, and contained the the SCriptManager control. MicrosoftAjax.js, and Microsoft.debug.js If not using an UpdatePanel, make sure to set the EnablePartialRendering property of the script manager to false. That way the js file required by the form to support the update panel, won't be downloaded as part of the page.

Tools:
The Microsoft AJAX Library is a nice Javascript progragaming framework even if not using AJAX. The javascript debugging features of vs2008 are usefull in debugging client-side AJAX.

You can also debug and explore AJAX with Fiddler, it allows to find out exactly what is going on with an AJAX application, it's a web debugging proxy that captures all the HTTP and HTTPS traffic between the web browser and server, can be used with any broswer but closely integrated with IE.
Firebug, for firefox lets you explore the javascript and it's interaction with page elements, has a nice XML/HTTP spy feature, and proivdes rich debugging information.



The rendered page:

Controls within an update panel are updated, they are the only ones 'flashing'.

The rendered page will included a few script blocks with source set to virutal script files of axd format, those are the client library, and the lib used by the form to implement the UpdatePanel, and any other script block required by the server controls themselves.

During an AJAX request, the code behind specific to the events of the controls in the update panel will be executed just as they would for a full page post back, this is done by the UpdatePanel during a AJAX request (Partial-PageProcessing).

Comments

Popular posts from this blog

Rxjs Forkjoin vs Zip

These Rxjs combination operators are handy to make Rest calls in parallel and combine their results. Both take n observables and will return the results, with the difference that forkJoin will complete even if one of the nested observables errors of completes.

React JS Patterns

React JS is always evolving, and evolving quickly. These evolutions can be very significant ones, for example, the addition of hooks. React has a lot of code patterns, often these patterns are motivated by the DRY and/or the open-close principle. These patterns sometimes come in to replace a previous one, yet the previous ones still stays in use, as a consequence, the list of patterns keep growing. The goal of the next few posts will be to list the patterns commonly used in React JS developpement. Some patterns are more specific to JSX and I will start with these, and maybe add patterns specific to Redux.

Object.create vs. Object.Assign

The two functions return a new Object but with a difference. Object.assign will go through an enumerable and copy it's properties. Object.create will create a new empty object but link it's proto chain to the old object. One way to view this is with JSON.stringify(newCreatedObject) this would return an empty object, since all the properties are not part of the object's own properties, but inherited through prototype inheritance. In both case, the advantage is it allows to extended existing objects without modifying the original. This is particularly important when receiving arguments from a caller, in this case it's better to use these methods instead of modifying the caller's object since he might have planned to use it again later, expecting it to be in it's original state.