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

  • Home
  • SEARCH
  • 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 47647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:09:20+00:00 2026-05-10T16:09:20+00:00

Part of the series of controls I am working on obviously involves me lumping

  • 0

Part of the series of controls I am working on obviously involves me lumping some of them together in to composites. I am rapidly starting to learn that this takes consideration (this is all new to me!) 🙂

I basically have a StyledWindow control, which is essentially a glorified Panel with ability to do other bits (like add borders etc).

Here is the code that instantiates the child controls within it. Up till this point it seems to have been working correctly with mundane static controls:

    protected override void CreateChildControls()     {         _panel = new Panel();          if (_editable != null)             _editable.InstantiateIn(_panel);          _regions = new List<IAttributeAccessor>();         _regions.Add(_panel);     } 

The problems came today when I tried nesting a more complex control within it. This control uses a reference to the page since it injects JavaScript in to make it a bit more snappy and responsive (the RegisterClientScriptBlock is the only reason I need the page ref).

Now, this was causing "object null" errors, but I localized this down to the render method, which was of course trying to call the method against the [null] Page object.

What’s confusing me is that the control works fine as a standalone, but when placed in the StyledWindow it all goes horribly wrong!

So, it looks like I am missing something in either my StyledWindow or ChildControl. Any ideas?

Update

As Brad Wilson quite rightly pointed out, you do not see the controls being added to the Controls collection. This is what the _panel is for, this was there to handle that for me, basically then override Controls (I got this from a guide somewhere):

    Panel _panel;    // Sub-Control to store the "Content".     public override ControlCollection Controls     {         get         {             EnsureChildControls();             return _panel.Controls;         }     } 

I hope that helps clarify things. Apologies.

Update Following Longhorn213’s Answer

Right, I have been doing some playing with the control, placing one within the composite, and one outside. I then got the status of Page at event major event in the control Lifecycle and rendered it to the page.

The standalone is working fine and the page is inited as expected. However, the one nested in the Composite is different. It’s OnLoad event is not being fired at all! So I am guessing Brad is probably right in that I am not setting up the control hierarchy correctly, can anyone offer some advice as to what I am missing? Is the Panel method not enough? (well, it obviously isn’t is it?!) 😀

Thanks for your help guys, appreciated 🙂

  • 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. 2026-05-10T16:09:20+00:00Added an answer on May 10, 2026 at 4:09 pm

    Solved!

    Right, I was determined to get this cracked today! Here were my thoughts:

    • I thought the use of Panel was a bit of a hack, so I should remove it and find out how it is really done.
    • I didn’t want to have to do something like MyCtl.Controls[0].Controls to access the controls added to the composite.
    • I wanted the damn thing to work!

    So, I got searching and hit MSDN, this artcle was REALLY helpful (i.e. like almost copy ‘n’ paste, and explained well – something MSDN is traditionally bad at). Nice!

    So, I ripped out the use of Panel and pretty much followed the artcle and took it as gospel, making notes as I went.

    Here’s what I have now:

    • I learned I was using the wrong term. I should have been calling it a Templated Control. While templated controls are technically composites, there is a distinct difference. Templated controls can define the interface for items that are added to them.
    • Templated controls are very powerful and actually pretty quick and easy to set up once you get your head round them!
    • I will play some more with the designer support to ensure I fully understand it all, then get a blog post up 🙂
    • A ‘Template’ control is used to specify the interface for templated data.

    For example, here is the ASPX markup for a templated control:

    <cc1:TemplatedControl ID='MyCtl' runat='server'>     <Template>         <!-- Templated Content Goes Here -->     </Template> </cc1:TemplatedControl>    

    Heres the Code I Have Now

    public class DummyWebControl : WebControl {     // Acts as the surrogate for the templated controls.     // This is essentially the 'interface' for the templated data. } 

    In TemplateControl.cs…

        ITemplate _template;     // Surrogate to hold the controls instantiated from      // within the template.     DummyWebControl _owner;      protected override void CreateChildControls()     {         // Note we are calling base.Controls here         // (you will see why in a min).         base.Controls.Clear();         _owner = new DummyWebControl();          // Load the Template Content         ITemplate template = _template;         if (template == null)             template = new StyledWindowDefaultTemplate();         template.InstantiateIn(_owner);          base.Controls.Add(_owner);         ChildControlsCreated = true;     } 

    Then, to provide easy access to the Controls of the [Surrogate] Object:

    (this is why we needed to clear/add to the base.Controls)

        public override ControlCollection Controls     {         get         {             EnsureChildControls();             return _owner.Controls;         }     } 

    And that is pretty much it, easy when you know how! 🙂

    Next: Design Time Region Support!

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

Sidebar

Ask A Question

Stats

  • Questions 62k
  • Answers 62k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You should detect the WM_CONTEXTMENU windows message by specifying a… May 11, 2026 at 10:13 am
  • added an answer It sounds like your UserControl is only useful if it… May 11, 2026 at 10:13 am
  • added an answer I think the common concensus would be use a custom… May 11, 2026 at 10:13 am

Related Questions

Part of the series of controls I am working on obviously involves me lumping
Part of the install for an app I am responsible for, compiles some C
Part of the setup routine for the product I'm working on installs a database
Part of the development team I work with has been given the challenge of
Part of the system I'm working on at the moment involves a log in
As part of the publishing best practices I came up with my own, I
As part of the Nant copy task, I would like to change the properties
As part of the base class for some extensive unit testing, I am writing
I read the part of the docs and saw that the ConfigParser returns a
As a part of the signup process for my online application, I'm thinking of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.