TAILIEUCHUNG - ASP.NET 4 Unleased - p 166

Lớp ImageItem chỉ là một lớp và không có nguồn gốc từ lớp Control cơ sở. Bởi vì các lớp ImageItem không gì khác hơn là đại diện cho một vài tài sản, không có lý do để làm cho nó điều khiển toàn diện. Các trang trong Ví dụ 36,29 minh hoạ cách bạn có thể sử dụng ImageRotator | 1624 CHAPTER 36 Building Custom Controls protected override void RenderContents HtmlTextWriter writer if 0 Random rnd new Random Imageitem img ImageItem _imageItems public class ImageItem private string _imageUrl private string _alternateText public string ImageUrl get return _imageUrl set _imageUrl value public string AlternateText get return _alternateText set _alternateText value The ImageItem class is just a class and does not derive from the base Control class. Because the ImageItem class does nothing more than represent a couple of properties there is no reason to make it a full-blown control. The page in Listing illustrates how you can use the ImageRotator control to display different images randomly. From the Library of Wow eBook Working with Control Property Collections 1625 LISTING @ Page Language C Trace true @ Register TagPrefix custom Namespace myControls DOCTYPE html PUBLIC - W3C DTD XHTML Transitional EN http TR xhtml1 DTD html xmlns http 1999 xhtml head id Head1 runat server title Show ImageRotator title head body form id form1 runat server div custom ImageRotator id ImageRotator1 Runat server custom ImageItem ImageUrl AlternateText Image 1 custom ImageItem ImageUrl AlternateText Image 2 custom ImageItem ImageUrl AlternateText Image 3 custom ImageRotator div form body html 36 The page in Listing has tracing enabled. If you look in the Control Tree section you see that the ImageRotator control does not contain any child controls see Figure . FIGURE The page control tree. From the Library of Wow eBook 1626 CHAPTER 36 Building Custom Controls Using the .

Đã 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.