Bây giờ bạn đã sử dụng tất cả các kiểm soát trong các phần mở rộng máy chủ Ajax, và kết quả là một ứng dụng được thêm rất nhiều hấp dẫn và đáp ứng hơn so với khi bạn bắt đầu. Trên đường đi, bạn chọn một tập hợp các thực hành tốt nhất | 138 CHAPTER 4 Exploring the Ajax server extensions You ve now used every control in the Ajax server extensions and the result is an application that is far more engaging and responsive than when you started. Along the way you picked up a collection of best practices for getting the most out of the extensions and you also got a glimpse into how the ScriptManager works under the hood. But you re not done yet. Even the best applications contain errors or raise exceptions. Error handling Things have been working smoothly so far but in the real world errors and exceptions occur. To wrap up this chapter let s examine what you have at your disposal to make handling these occurrences more manageable. Listing shows a snippet of code that purposely throws an exception after the user has selected a new music genre from the drop-down list. Listing Throwing an exception to see how the page handles it protected void Genres_SelectedIndexChanged object sender EventArgs e UpdateGenre throw new Exception Look out Earlier you set the AutoPostBack property of this control to true and also placed it in an UpdatePanel. This means the postback that originates from here is asynchronous also known as an Ajax postback. Typically depending on the settings of the file an error during a normal postback results in the stack trace and error information being shown on the screen. This time the browser relays the exception information in a dialog box see figure . This result can be informative for developers but displaying the same message from the exception back to the user isn t always the best idea. Fortunately the Figure By default exceptions that occur during asynchronous postbacks are displayed in alert dialogs. ScriptManager control throws an event called AsyncPostBackError that provides you with an opportunity to update the text in the dialog box before it s presented to the user. Listing demonstrates how a handler for the event is registered and the