TAILIEUCHUNG - ASP.NET 4 Unleased - p 173

UpdatePanels và JavaScript Bạn phải chăm sóc đặc biệt khi sử dụng JavaScript với các điều khiển UpdatePanel. Nếu bạn sử dụng các phương pháp tiêu chuẩn của lớp ClientScriptManager để làm việc với JavaScript, họ sẽ thất bại khi được gọi trong một yêu cầu không đồng bộ. | 1694 CHAPTER 38 Using Server-Side AJAX Runat server asp Button id btnSearch Text Search OnClick btnSearch_Click Runat server ContentTemplate asp UpdatePanel asp UpdatePanel id upResults UpdateMode Conditional Runat server ContentTemplate Results Time T br asp GridView id grdResults runat server ContentTemplate asp UpdatePanel div form body html UpdatePanels and JavaScript You must take special care when using JavaScript with UpdatePanel controls. If you use the standard methods of the ClientScriptManager class for working with JavaScript they will fail when called during an asynchronous request. For example I often use the method from my server-side code to inject a JavaScript script into a page dynamically. The page in Listing contains a Delete All Files button. When you click the button and the method returns true a JavaScript alert box displays the message All Files Deleted Successfully see Figure . From the Library of Wow eBook Using the UpdatePanel Control 1695 FIGURE Displaying a JavaScript alert. LISTING @ Page Language C DOCTYPE html PUBLIC - W3C DTD XHTML Transitional EN http TR xhtml1 DTD script runat server protected void btnDeleteAll_Click object sender EventArgs e if true string script @ alert All Files Deleted Successfully filesDeleted script true script html xmlns http 1999 xhtml head runat server title Show Alert title head body form id form1 runat server div 38 asp Button id btnDeleteAll Text Delete All Files OnClick btnDeleteAllClick From the Library of Wow eBook 1696 CHAPTER 38 Using Server-Side AJAX Runat server div form body html Unfortunately the page in Listing does not work when the Button control is wrapped in an UpdatePanel. The JavaScript alert never appears after you click the .

149    3    0    12-08-2020
17    3    0    12-08-2020
16    6    0    12-08-2020
16    4    0    12-08-2020