tailieunhanh - ASP.NET 4 Unleased - p 13

Sử dụng Client Scripts với nút điều khiển Tất cả ba nút điều khiển hỗ trợ một tài sản OnClientClick. Bạn có thể sử dụng tài sản để thực hiện bất kỳ mã phía máy khách mà bạn cần khi nút được nhấn. Các trang trong Ví dụ 2,18 minh họa làm thế nào bạn có thể sử dụng tài sản OnClientClick để hiển thị một hộp thoại xác nhận (xem hình ). | 94 CHAPTER 2 Using the Standard Controls Using Client Scripts with Button Controls All three Button controls support an OnClientClick property. You can use this property to execute any client-side code that you need when a button is clicked. The page in Listing illustrates how you can use the OnClientClick property to display a confirmation dialog box see Figure . LISTING @ Page Language C DOCTYPE html PUBLIC - W3C DTD XHTML Transitional EN http TR xhtml1 DTD script runat server protected void btnDelete_Click object sender EventArgs e All pages deleted script html xmlns http 1999 xhtml head id Head1 runat server title Button OnClientClick title head body form id form1 runat server div asp Button id btnDelete Text Delete Website OnClick btnDelete_Click OnClientClick return confirm Are you sure Runat server br br asp Label id lblResult Runat server div form body html From the Library of Wow eBook Submitting Form Data 95 FIGURE Displaying a client-side confirmation dialog box. 2 In Listing the Button control includes an OnClientClick property which executes a JavaScript script when you click the button on the client. The script displays a confirmation dialog box. If the confirmation box returns False the button click is canceled and the form containing the button is not posted to the server. Because the button controls like most controls support expando attributes you can handle other client-side events simply by adding an arbitrary attribute to the control. If Framework does not recognize an attribute declared on a button control the framework simply passes the attribute to the browser. For example the page in Listing contains a button control that includes onmouseover and onmouseout attributes. When you hover your mouse over the button the text displayed in the button is changed. LISTING @ Page Language C .

TÀI LIỆU LIÊN QUAN
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.