Home > ASP.NET MVC > ASP.NET MVC # 19 When to use Ajax and When not to use ajax in ASP.NET MVC

ASP.NET MVC # 19 When to use Ajax and When not to use ajax in ASP.NET MVC

Hi Geeks,

AJAX = Asynchronous JavaScript and XML.

AJAX is the art of exchanging data with a server, and update parts of a web page – without reloading the whole page.

In this article we will see where / when to use ajax and when to not in ASP.NET MVC.

1) When to use Ajax

Asynchronous requests have their advantages and can make users feel like they are in control ofyour application rather than the other way round. Some of the advantages include:  
-> Partial Rendering of a Complex Page: If a particular page you’re working on (a portal page, for instance) has a lot of dynamic information on it, it might be advantageous to avoid doing a full postback to the server simply to update a small section of the page. A user may want to filter a list of information,

For example,                                                                                                                               By a selection in a dropdown. Refreshing the entire page (database calls and all) in this case can create a performance bottleneck and give the impression that the site is slow or cumbersome to work with.

-> It Looks Fast: Ajax requests, when properly set up and executed, can be quite fast. When you couple this with the lack of a page blink (from a postback), users tend to come away with the impression that your site is much more responsive even when the response time is roughly the same. This lends to a greater sense of control and interactivity

-> Reduced Server Load: As discussed in the first bullet, careful use of Ajax can reduce the overall load on your server and database. This isn’t confined to complex pages but applies to the entire site operation. If the main functional elements of a page can be confined to smaller
Ajax operations, it can significantly cut down on database and/or server connections.

-> It’s Asynchronous: The fact that Ajax is asynchronous (that’s the A in Ajax) allows you some flexibility in terms of long-running operations or executing things that a user may otherwise not want to wait around for.

For Example ,                                                                                                                       Google’s Gmail application (one of the first major, well-knownAjax applications) is a prime example of clever use of asynchronous requests. Most of the time you’re not aware of the page operations as you read your messages or navigate the site, only while you’re occupied with what’s onscreen, Gmail is constantly checking the server forupdates to conversations (mail messages) and IM status (if you have that enabled).

2) When not to use ajax

-> JavaScript Must Be Enabled on the Client: For many developers, this is a very foreign concept:
A user might actually turn off scripting in his or her browser. There are a lot of reasons
that people do this, not the least of which is security. Clever programming of JavaScript leads
to cross-site scripting attacks, stealing cookies, and even planting various password-stealing
Trojans. Many people disable JavaScript as a matter of habit, and these people will be unable
to use your site if it relies on Ajax.      

-> The Back Button: Usability is a primary feature of every website, and your
browser’s history and Back button are primary considerations. Users should be able to
“undo” their navigation and step backward from whence they came. Ajax doesn’t (normally)
allow for this. If you re-render an entire page using Ajax, or change the display significantly,
you’re presenting information that may not reflect the URL properly. Thus, a user will lose
his or her crumb trail through your site, and navigation becomes somewhat useless.

Hope this helps.. Smile


Categories: ASP.NET MVC
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: