VS 2008 Using the ITemplate in a UserControl and getting a design time rendoring error-VBForums
Results 1 to 5 of 5

Thread: Using the ITemplate in a UserControl and getting a design time rendoring error

  1. #1

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,633

    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

  2. #2

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,633

    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

  3. #3
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

    Re: Using the ITemplate in a UserControl and getting a design time rendoring error

    Scroll down to the comments section of this page.



    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

  4. #4

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,633

    Re: Using the ITemplate in a UserControl and getting a design time rendoring error

    Quote Originally Posted by mendhak View Post
    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

  5. #5

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.