TAILIEUCHUNG - ASP.NET 4 Unleased - p 175

Khi bạn điều hướng đến một bộ phim mới, cả hai thanh tiêu đề trình duyệt, và trang web thuộc nhóm được cập nhật để hiển thị tiêu đề của bộ phim mới (hình 38,12). Tiêu đề và nhóm được cập nhật bằng cách một mục dữ liệu mà đại diện cho các tựa phim trong postback không đồng bộ. | 1714 CHAPTER 38 Using Server-Side AJAX var prm prm_pageLoaded function prm_pageLoaded sender args if var movieTitle Head1 assign browser title bar movieTitle assign heading get hTitle .innerHTML movieTitle script body html When you navigate to a new movie both the browser title bar and the page heading are updated to display the title of the new movie see Figure . The title and heading are updated by passing a data item that represents the movie title during the asynchronous postback. FIGURE Updating a page s header and title asynchronously. Handling UpdatePanel Errors Gracefully Sometimes things go terribly wrong. The Internet gets clogged an application s database server goes down and so on. How do you recover from these types of errors gracefully in an Ajax application From the Library of Wow eBook Using the UpdatePanel Control 1715 By default if an error occurs during an asynchronous postback a JavaScript alert box appears that displays an error message. This is a jarring experience in a production application. You have several options for avoiding this default experience You can configure a custom error page you can handle the error on the server side or you can handle the error on the client side. Let s examine each of these options. First if you configure a custom error page for your application by default the custom error page applies to asynchronous postback errors. You enable a custom error page by adding the following element to the section of your web configuration file customErrors mode On defaultRedirect This element enables a custom error page for both local and remote requests. Any unhandled exceptions in any page cause the browser to be redirected to a page named . The page in Listing throws an exception when you click the button located in the UpdatePanel .