Đang chuẩn bị liên kết để tải về tài liệu:
Wrox Professional Web Parts and Custom Controls with ASP.NET 2.0 phần 8

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Trình dịch JIT cung cấp thêm khả năng bảo mật, tính an toàn lúc thực thi và khả năng chạy trên nhiều nền tảng (Microsoft cho biết sẽ dùng một tập con chuẩn hoá của .NET Framework - được gọi là nền tảng ngôn ngữ chung” - để xây dựng một thể hiện trên FreeBSD). Nếu trình JIT cho mã ngôn ngữ trung gian làm bạn liên tưởng đến Java thì cũng đừng hoang mang, Microsoft đã lẳng lặng dùng ngôn ngữ trung gian trong Vbasic và hầu hết các phần mềm ứng dụng của mình (kể cả Office)từ nhiều. | Chapter 9 Private _ChildControls As ArrayList Public Property ChildControls As ArrayList Get Return _ChildControls End Get Set ByVal value As ArrayList _ChildControls value End Set End Property In C private ArrayList _ChildControls public ArrayList ChildControls get return _ChildControls set _ChildControls value On the class declaration you must specify this repository property as the default property for your control as this Visual Basic 2005 code does ParseChildren True ChildControls _ ToolboxData 0 BookInfo runat server 0 BookInfo _ Public Class BookInfo In C ParseChildren true ChildControls ToolboxData 0 BookInfo runat server 0 BookInfo public class BookInfo In your Render method you could iterate through the ChildControls collection having each control render itself by calling its RenderControl method. In Visual Basic 2005 the code looks like this Protected Overrides Sub Render ByVal writer As System.Web.UI.HtmlTextWriter For Each ctl As Control In Me.ChildControls ctl.RenderControl writer Next End Sub In C protected override void Render System.Web.UI.HtmlTextWriter writer foreach Control ctl in this.ChildControls 298 Adding Advanced Functionality ctl.RenderControl writer While this provides a simple mechanism for generating constituent controls it doesn t really address the issue of handling multiple properties with complex datatypes. Instead it creates a single property to hold all complex objects. It is better to have a dedicated property for each object. It is also better to have some mechanism that allows you to manage the processing of the tags nested in the custom control rather than just blindly rendering them. Handling Complex Content The next step is to handle multiple complex properties on a single control and provide a mechanism for managing those elements as they are added. As the example for this section the BookInfo control is extended to support the following nested tags The Author tag with a first name and a last name The Titles tag with the .