探讨ASP.NET 2.0中的Web控件改进技术
作者: 朱先忠 编译, 出处:天极, 责任编辑: 叶江,
2007-01-30 11:15
ASP.NET 2.0并没有抛弃1.1版本中的任何现有控件,而是增加了一组新的控件;同时还引入了若干新的控件开发技术。本系列文章将对这些内容展开全面探讨。
你可能已经猜出,对于你想定义的每个模板和每个模板组,都要重复这一操作。最终结果是,我的o_TemplateGroups对象中填充了我的模板中定义的所有信息—而这正是我在这个属性中所返回的内容。

图3.在模板编辑方式的EmailContact控件
现在,我重新编译并转到我的测试页面。当我右击EmailContact控件时,我将看到“EditTemplates”被添加到快捷方式菜单中。子菜单下的列表将显示我在设计器类中所定义的模板组,而当我选择“Surrounding Templates”组时,我会看到类似图3所示的内容。现在,你可以看到我手工地添加到这两个模板中的控件;而事实上,我现在就可以把其它控件从工具箱直接拖动到其上。再次右击鼠标并选择“Edit Templates”将返回到标准控件视图并且在控件中显示该模板内容。
另外还注意,一个“Edit Templates”链接也被自动地添加到该控件的灵敏标签上。如果以前不存在一个灵敏标签,那么,当我把模板编辑代码添加到设计器类上时,它会自动地为我创建一个。
下面是完整的模板编辑代码:
| Public Overrides Sub Initialize(ByVal Component As IComponent) MyBase.Initialize(Component) ' Turn on template editing SetViewFlags(ViewFlags.TemplateEditing, True) End Sub Private o_TemplateGroups As TemplateGroupCollection = Nothing Public Overrides ReadOnly Property TemplateGroups() _ As TemplateGroupCollection Get If o_TemplateGroups Is Nothing Then o_TemplateGroups = New TemplateGroupCollection() Dim o_TemplateGroup As TemplateGroup Dim o_TemplateDefinition As TemplateDefinition Dim ctl As EmailContact2 = CType(Component, _ EmailContact2) o_TemplateGroup = New TemplateGroup( _ "Surrounding Templates") o_TemplateDefinition = New TemplateDefinition( _ Me, "Header Template", ctl, "HeaderTemplate", True) o_TemplateGroup.AddTemplateDefinition( _ o_TemplateDefinition) o_TemplateDefinition = New TemplateDefinition( _ Me, "Footer Template", ctl, "FooterTemplate", True) o_TemplateGroup.AddTemplateDefinition( _ o_TemplateDefinition) o_TemplateGroups.Add(o_TemplateGroup) End If Return o_TemplateGroups End Get End Property |
- 本文关键词:

