tailieunhanh - Manning ASP.NET AJAX in Action PHẦN 4

Nếu bạn chương trình trong NET sử dụng C # , sau đó bạn có thể đã nghe nói về phương pháp vô danh, mà không thể được gọi là đóng cửa nhưng thực hiện một kỹ thuật tương cấu hình các tập tin cho hội nhập Ajax. | 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

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.