【问题标题】:Templated Control - content is not allowed between the opening and closing tags模板化控件 - 开始和结束标签之间不允许有内容
【发布时间】:2010-09-09 19:42:28
【问题描述】:

我正在尝试运行 MSDN 提供的模板化用户控件示例。代码如下:

所以根据 MSDN,这应该实现如下:

<%@ Register Assembly="MyAssembly" Namespace="MyAssembly.Controls" TagPrefix="abs" %>
<abs:TemplatedFirstControl id = "First"  runat=server
                           Text= "The time on the server is "  >
      <FirstTemplate>
          <h3><font face="Verdana" color = "red">
                 <%# Container.Text %> <%# Container.DateTime %>
              </font>
          </h3>
      </FirstTemplate>      
    </abs:TemplatedFirstControl>

设计师抱怨TemplatedFirstControl的开始和结束标签之间不允许有内容,并且不支持FirstTemplate。那么缺少什么?我逐字复制了 MSDN 的代码

MSDN 文章:http://msdn.microsoft.com/en-us/library/aa720695%28v=VS.71%29.aspx

【问题讨论】:

  • 你对前缀abs的定义是什么?
  • 在 .aspx 中的
  • 考虑编辑问题以包含该注册标记,以及指向 MSDN 文章的链接。是否还需要创建任何 web.config 条目?
  • 没有。这应该很简单。

标签: c# asp.net controls


【解决方案1】:

对于遇到相同问题的任何人,我发现将以下属性添加到 FirstTemplate 属性解决了我的问题:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public ITemplate FirstTemplate 
{
    get
    {
        return firstTemplate;
    }
    set
    {
        firstTemplate = value;
    }
}

【讨论】:

    【解决方案2】:

    听起来编译器没有识别出 FirstTemplate 是 TemplatedFirstControl 的有效子元素。检查以下内容:

    • FirstTemplate 是 TemplatedFirstControl 的代码隐藏类的公共属性吗?
    • 是否定义了一个从 Control 派生并实现 INamedContainer 的公共子模板控件类?
    • FirstTemplate 属性是否使用 TemplateContainer 属性修饰?
    • 该属性是否正确指定了子模板控件的类型?

    【讨论】:

    • 如前所述,我使用了 MSDN 文章中的确切代码。我在这里重新创建了它,但有人编辑了我的帖子并将其全部发表了评论。 TemplatedFirstControl 不是用户控件。这是一个服务器控制类。但在我看来,所有这些基础都被覆盖了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-04
    • 1970-01-01
    • 1970-01-01
    • 2019-08-26
    • 2016-02-12
    相关资源
    最近更新 更多