Home All Groups Group Topic Archive Search About

Templated User Control & intellisense

Author
12 Dec 2005 9:10 PM
Frédéric Mayot
Hi,
I built a very simple templated user control but unfortunately, the template
"Content" is not recognized by intellisense and it says that my component
"SubForm" is not supposed to contain anything.
Any idea ?
Thanks

SubForm.ascx-------------------------
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SubForm.ascx.cs"
Inherits="SubForm" %>
<asp:PlaceHolder runat="server" ID="pl" />


SubForm.ascx.cs----------------------
public partial class SubForm : MyBaseUserControl {

  protected void Page_Init() {
    if (content != null) {
      Content container = new Content();
      Content.InstantiateIn(container);
      pl.Controls.Add(container);
    }
  }

  private ITemplate content = null;

  [TemplateContainer(typeof(Content)),
  TemplateInstance(TemplateInstance.Single)]
  public ITemplate Content {
    get { return this.content; }
    set { this.content = value; }
  }
}

public class Content : Control, INamingContainer{}

Using---------------------------------
<puc:SubForm runat="server">
<Content>
  <asp:Label runat="server" />
  something else
  etc.
</Content>
</puc:SubForm>

Author
13 Dec 2005 12:56 PM
Brock Allen
You also need to apply
[PersistenceMode(PersistenceMode.InnerProperty)]]

to your ITemplate property and the

[ParseChildren(true)]
[PersisteChildresn(false)]

to your control class.

-Brock
DevelopMentor
http://staff.develop.com/ballen

Show quoteHide quote
> Hi,
> I built a very simple templated user control but unfortunately, the
> template
> "Content" is not recognized by intellisense and it says that my
> component
> "SubForm" is not supposed to contain anything.
> Any idea ?
> Thanks
> SubForm.ascx-------------------------
> <%@ Control Language="C#" AutoEventWireup="true"
> CodeFile="SubForm.ascx.cs"
> Inherits="SubForm" %>
> <asp:PlaceHolder runat="server" ID="pl" />
> SubForm.ascx.cs----------------------
> public partial class SubForm : MyBaseUserControl {
> protected void Page_Init() {
> if (content != null) {
> Content container = new Content();
> Content.InstantiateIn(container);
> pl.Controls.Add(container);
> }
> }
> private ITemplate content = null;
>
> [TemplateContainer(typeof(Content)),
> TemplateInstance(TemplateInstance.Single)]
> public ITemplate Content {
> get { return this.content; }
> set { this.content = value; }
> }
> }
> public class Content : Control, INamingContainer{}
>
> Using---------------------------------
> <puc:SubForm runat="server">
> <Content>
> <asp:Label runat="server" />
> something else
> etc.
> </Content>
> </puc:SubForm>