Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3220808
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:48:14+00:00 2026-05-17T15:48:14+00:00

I want to create a control just like a Panel . I want my

  • 0

I want to create a control just like a Panel.

I want my control to accept some controls as childs without typing the template name, just like the Panel, as shown here:

<asp:Panel runat="server">
    My content
    <div>Content</div>
</asp:Panel>

I have controls with content inside without telling what is the ITemplate.

I basically want to convert this

<my:MyControl runat="server">
    <ContentTemplate>
        My content
        <div>Content</div>
    </ContentTemplate>
</my:MyControl>

Into this

<my:MyControl runat="server">
    My content
    <div>Content</div>
</my:MyControl>

Here is what I’ve got:

public class MyControl : CompositeControl
{
    [TemplateInstance(TemplateInstance.Single)]
    public ITemplate Content { get; set; }

    protected override void CreateChildControls()
    {
        base.CreateChildControls();

        Content.InstantiateIn(this);
    }
}

The above works with <Content></Content> tags inside the control, but without it doesn’t work. And the attribute isn’t doing anything at all (I guess). What’s missing?

How can I achieve it? Any hints? Why does Panel support this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:48:14+00:00Added an answer on May 17, 2026 at 3:48 pm

    I’m writting this from memory but I believe the answer is a simple as decorating your control class with the attributes ParseChildrenAttribute and PersistChildrenAttribute and you do not need to work with templates as you are proposing.

    ParseChildrenAttribute.ChildrenAsProperties specifies whether the parser should treat the nested content of the control tag as properties. Setting this to false will make the parser not to try to map the tags to property names.

    The PersistChildrenAttribute will tell the parser to treat the nested content as controls and the parsed controls will be added as child controls to your custom panel control.

    The code for your control would then look something like this:

    [ParseChildren(false)]
    [PersistChildren(true)]
    public class MyControl : CompositeControl 
    {
        public override void RenderBeginTag(HtmlTextWriter writer)
        {
            base.RenderBeginTag(writer); // TODO: Do something else here if needed
        }     
    
        public override void RenderEndTag(HtmlTextWriter writer)
        {
            base.RenderEndTag(writer); // TODO: Do something else here if needed
        }
    } 
    

    For reference you could fire up .NET Reflector and look at the implementation of the Panel control.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i want to create a control for my activty which is just like
OK, I want to create a control that is like a Stackpanel with TextBlock
I'm trying to create a CollapsiblePanel control, which is essentially just a panel which
Lets pretend that for some reason I want to create a custom control that
I want to create custom control (let's name it DesignPanel ) that will allow
In Silverlight, when you want to create a control dynamically, you must add the
I want to create a custom control in C#. But every time I have
ASP.Net 3.5 I want to create a user control that contains the ListView and
I want to create a Silverlight 2 control that has two content areas. A
I want to create a slider to control the volume of the media player.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.