ASP.NET 4 Unleased - p 8

Tôi đã nghe nói nó lập luận rằng code-behind trang được cấp trên cho các trang đơn tập tin bởi vì các trang codebehind cho phép bạn thêm sạch riêng biệt giao diện người dùng của bạn từ logic ứng dụng của bạn. Vấn đề với lập luận này là sự biện minh bình thường để tách giao diện người dùng của bạn từ logic ứng dụng của bạn là mã tái sử dụng. Xây dựng các trang code-behind không thúc đẩy sử dụng lại mã. . | 44 CHAPTER 1 Overview of the Framework I ve heard it argued that code-behind pages are superior to single-file pages because code-behind pages enable you to more cleanly separate your user interface from your application logic. The problem with this argument is that the normal justification for separating your user interface from your application logic is code reuse. Building code-behind pages doesn t promote code reuse. A better way to reuse application logic across multiple pages is to build separate component libraries. Part IV of this book explores this topic. Ultimately it is a personal preference. The majority of enterprise projects that we have worked on utilize code-behind pages but single-file pages are perfectly acceptable under the right circumstances. Handling Page Events Whenever you request an page a particular set of events is raised in a particular sequence. This sequence of events is called the page execution lifecycle. For example we have already used the Page Load event in previous code samples. You normally use the Page Load event to initialize the properties of controls contained in a page. However the Page Load event is only one event supported by the Page class. Following is the sequence of events raised whenever you request a page 1. PreInit 2. Init 3. InitComplete 4. PreLoad 5. Load 6. LoadComplete 7. PreRender 8. PreRenderComplete 9. SaveStateComplete 10. Unload Why so many events Different things happen and different information is available at different stages in the page execution lifecycle. For example View State is not loaded until after the InitComplete event. Data posted to the server from a form control such as a TextBox control is also not available until after this event. Ninety-nine percent of the time you won t handle any of these events except for the Load and the PreRender events. The difference between these two events is that the Load event happens before any control events and the PreRender event happens .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
7    70    2    29-04-2024
19    248    1    29-04-2024
Đã 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.