Mọi thứ đã được làm việc suôn sẻ cho đến nay, nhưng trong thế giới thực, các lỗi và các ngoại lệ xảy ra. Để kết thúc chương này, chúng ta hãy xem xét những gì bạn có theo ý của bạn để làm cho việc xử lý các sự cố dễ quản lý hơn. | 252 CHAPTER 7 Under the hood of the UpdatePanel Now when a request is made you check to see if you re in the middle of an asynchronous postback. If so then you cancel the latest request to give precedence priority to the previous postback. To accomplish this make the updates to the onInitializeRequest handler shown in listing . Listing Aborting and canceling requests during partial updates function onInitializeRequest sender args var prm var details postBackElementID .id Save instance of PageRequestManager B if --------1 if .id Abort ec. i in asychronous v Tft H Y T- _ f-x C T M u- 1 4- else C postback true I ặp Cancel details canceled latest request var row createEventRow initializeRequest details get clientEvents .appendChild row We may be lazy but we pride ourselves on being proactively lazy. This example makes a copy of an instance of the B PageRequestManager so you can use it later in the function without all the extra typing. Next you check to see if you re currently in an asynchronous postback by getting the C isInAsyncPostBack property from the PageRequestManager. This makes sense because you want to abort and cancel a request only if you re currently in the middle of one. Finally if the Abort button wasn t the element that invoked the request you set the D cancel property to true to give priority to the previous request. Notifying the user Just before an asynchronous request is sent to the server the PageRequestManager raises the beginRequest event. Similar to the previous example the BeginRequest-EventArgs passed into this handler includes the postBackElement property. When raised this occurrence gives you the opportunity to notify the user about the upcoming postback before it begins. For lengthy operations what typically happens and is recommended is that the user is given a visual .