Using the ITemplate in a UserControl and getting a design time rendoring error
Hi,
Here's the code for a simple content usercontrol I am using:
Code:
public partial class ContentPanel : System.Web.UI.UserControl
{
[ParseChildren(true, "ContentTemplate")]
public class ContentContainer : Control, INamingContainer {}
private ITemplate _contentTemplate;
[TemplateContainer(typeof(ContentContainer), BindingDirection.TwoWay)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[TemplateInstance(TemplateInstance.Single)]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[EditorBrowsable(EditorBrowsableState.Never)]
public ITemplate ContentTemplate
{
get { return this._contentTemplate; }
set { this._contentTemplate = value; }
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if(this._contentTemplate != null)
{
ContentContainer container = new ContentContainer();
this._contentTemplate.InstantiateIn(container);
this.phContentTemplate.Controls.Add(container);
}
}
}
and the markup is:
Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ContentPanel.ascx.cs" Inherits="SvratchJScriptWeb.UserControls.ContentPanel" %>
<div id="divPanel" runat="server" style="width:300px">
<asp:PlaceHolder ID="phContentTemplate" runat="server" />
</div>
So in every page i use this the markup would be like:
Code:
<uc1:ContentPanel ID="ContentPanel1" runat="server">
<ContentTemplate>
other controls and stuff goes here
</ContentTemplate>
</uc1:ContentPanel>
This works at runtime...however the control fails to render at design time with the error:
Error Creating Control - ContentPanel1
Type 'System.Web.UI.UserControl' does not have a public property named 'ContentTemplate'
The odd thing is that the VS IDE intellisence can see that the template is called <ContentTemplate> and hightlights it when I type into the UI source designer...it just fails when looking at design time rendering :s
Has anyone seen this b4?
Woka
Re: Using the ITemplate in a UserControl and getting a design time rendoring error
Forgot to add that if I miss off the <ContentTemplate> tags in the page then it renders:
Code:
<uc1:ContentPanel ID="ContentPanel1" runat="server">
</uc1:ContentPanel>
When this happens the control gets renderd at design time.
The property ContentTemplate exists in my code, and intelisence inserts <ContentTemplate> for me...odd odd odd odd
:(
Woka
Re: Using the ITemplate in a UserControl and getting a design time rendoring error
Scroll down to the comments section of this page.
Quote:
Continuing from mj1856's comment, I found this combination of attributes gets it working in the designer:
[TemplateContainer(typeof(MessageContainer))]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ITemplate MessageTemplate
Re: Using the ITemplate in a UserControl and getting a design time rendoring error
Quote:
Originally Posted by
mendhak
Scroll down to the comments section of
this page.
Saw that link the other day...not much use tbh :( Still get the error. The attributes I have posted here are a combination of things people have said will make it work...but none do :(
Woka
Re: Using the ITemplate in a UserControl and getting a design time rendoring error
I am just trying to create my own very simple container control for use in my web app.
Woka