|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Templated User Control & intellisenseI 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> 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>
Result not expected with user control - any ideas why/
Problem adding attributes to DataListItem.. Role based security Tabbed control for ASP.NET pages Could not load type XXXXXX from assembly mscorlib Trouble with radio button list in Asp.net 1.1 datagrid value grouping The lowly data field DropDownList(ddlist) and TextBox(tbox) Find the source of an event |
|||||||||||||||||||||||