TAILIEUCHUNG - ASP.NET 4 Unleased - p 176

Khi làm việc với các UpdatePanel, bạn không bao giờ nên quên rằng phía máy chủ trang trải qua chu kỳ bình thường trang cuộc sống thực hiện nó bất cứ khi nào một postback không đồng bộ xảy ra. Nếu bạn thực hiện một cơ sở dữ liệu đắt tiền của bạn tra cứu trong Page_Load () phương pháp, đó là tra cứu xảy ra với mỗi cuộc gọi không đồng bộ với máy chủ của bạn. | 1724 CHAPTER 38 Using Server-Side AJAX NOTE To learn more about caching see Chapter 29 Caching Application Pages and Data. When working with the UpdatePanel you should never forget that the server-side page undergoes its normal page execution life cycle whenever an asynchronous postback occurs. If you perform an expensive database lookup in your Page_Load method that lookup occurs with each asynchronous call to your server. You can avoid performing unnecessary server-side work during an asynchronous postback by taking advantage of the ScriptManager control s IsInAsyncPostBack property. You can use this property to detect whether the page is executing in the context of a normal postback or an asynchronous postback. Using the Timer Control The AJAX Timer control enables you to refresh an UpdatePanel or the entire page on a timed basis. The Timer control has one important property Interval The amount of time in milliseconds between Tick events. The default value is 60 000 1 minute . The Timer control raises a Tick event every so many milliseconds depending on the value of its Interval property. If you don t associate the Timer control with an UpdatePanel the Timer posts the entire page back to the server performing a normal postback. For example the page in Listing posts the entire page back to the server every 2 seconds. LISTING @ Page Language C DOCTYPE html PUBLIC - W3C DTD XHTML Transitional EN http TR xhtml1 DTD html xmlns http 1999 xhtml head runat server title Timer Page title head body form id form1 runat server div asp ScriptManager ID ScriptManager1 runat server asp Timer ID Timer1 Interval 2000 runat server From the Library of Wow eBook Using the Timer Control 1725 The time is T div form body html A more typical use of the Timer control is to refresh an UpdatePanel control s content on a timed basis. For example the page in Listing .