开发者

Templated Control - content is not allowed between the opening and closing tags

开发者 https://www.devze.com 2023-01-15 06:49 出处:网络
I\'m trying to run the templated user control example provided by MSDN. Code is as follows: So according to MSDN this should implement as follows:

I'm trying to run the templated user control example provided by MSDN. Code is as follows:

So according to MSDN this should implement as follows:

<%@ Register Assembly="MyAssembly" Namespace="MyAssembly.Controls" TagPre开发者_如何学Cfix="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>

Designer complains that content is not allowed between the opening and closing tags of TemplatedFirstControl and that FirstTemplate is not supported. So what's missing? I duplicated MSDN's code verbatim

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


For anyone who has the same problem, I found that adding the following attributes to the FirstTemplate property solved the issue for me:

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


It sounds like the compiler is not recognizing that FirstTemplate is a valid child element of TemplatedFirstControl. Check the following:

  • Is FirstTemplate a public property of the codebehind class of TemplatedFirstControl?
  • Is there a public child template control class defined, that derives from Control and implements INamedContainer?
  • Is the FirstTemplate property decorated with a TemplateContainer attribute?
  • Does that attribute correctly specify the type of the child template control?
0

精彩评论

暂无评论...
验证码 换一张
取 消