Because traditional ASP.NET code does all its work on the web server, every time an action occurs in the
page the browser needs to post some data to the server, get a new copy of the page, and refresh the
display. This process, though fast, introduces a noticeable flicker. It also takes enough time that it isn’t
practical to respond to events that fire frequently, such as mouse movements or key presses.
Web developers work around these sorts of limitations using JavaScript, the only broadly supported
client-side scripting language. In ASP.NET, many of the most powerful controls use a healthy bit of
JavaScript. For example, the Menu control responds immediately as the user moves the mouse over
different subheadings. When you use the Menu control, your page doesn’t post back to the server until
the user clicks an item.
In traditional ASP.NET pages, developers use server controls such as Menu and gain the benefit of
the client-side script these controls emit. However, even with advanced controls, some postbacks are
unavoidable. For example, if you need to update the information on a portion of the page, the only way
to accomplish this in ordinary ASP.NET is to post the page back to the server and get an entirely new
HTML document. The solution works, but it isn’t seamless.
Restless web developers have responded to challenges like these by using more client-side code and
applying it in more advanced ways. One of the most talked about examples today is Ajax (Asynchronous
JavaScript and XML). Ajax is programming shorthand for a client-side technique that allows your page to
call the server and update its content without triggering a complete postback. Typically, an Ajax page
uses client-side script code to fire an asynchronous request behind the scenes. The server receives this
request, runs some code, and then returns the data your page needs (often as a block of XML markup).
Finally, the client-side code receives the new data and uses it to perform another action, such as
refreshing part of the page. Although Ajax is conceptually quite simple, it allows you to create pages that
work more like seamless, continuously running applications. Figure 1-3 illustrates the differences.
Ajax and similar client-side scripting techniques are nothing new, but in recent years they’ve begun
to play an increasingly important role in web development. One of the reasons is that the
XMLHttpRequest object—the plumbing that’s required to support asynchronous client requests—is
now present in the majority of modern browsers, including the following:
• Internet Explorer 5 and newer
• Netscape 7 and newer
• Opera 7.6 and newer
• Safari 1.2 and newer
• Firefox (any version)
• Google Chrome (any version)
However, writing the client-side script in such a way that it’s compatible with all browsers and
implementing all the required pieces (including the server-side code that handles the asynchronous
requests) can be a bit tricky. As you’ll see in Chapter 29, ASP.NET provides a client callback feature that
handles some of the work. However, ASP.NET also includes a much more powerful abstraction layer
named ASP.NET AJAX, which extends ASP.NET with impressive Ajax-style features. You’ll explore
ASP.NET AJAX in Chapter 30.
Hiç yorum yok:
Yorum Gönder