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 155949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:14:45+00:00 2026-05-11T10:14:45+00:00

I have a usercontrol that move dynamically on the CreateChildControls method some web controls.

  • 0

I have a usercontrol that move dynamically on the CreateChildControls method some web controls. When using this control into a page like :

<myControls:MyUserControl runat='server' ID='myUserControl' /> 

It works flawlessly.

But if I want to add that userControl dynamically into a page like :

<asp:UpdatePanel runat='server'>     <ContentTemplate>         <asp:PlaceHolder runat='server' ID='plhControls' />     </ContentTemplate> </asp:UpdatePanel> <asp:Button runat='server' ID='btnAdd' OnClick='btnAdd_Click' /> 

.cs

protected void btnAdd_Click(object sender, EventArgs e) {     MyUserControl myUserControl =(MyUserControl)LoadControl('~/Controls/MyUserControl.ascx');     myUserControl.ID = 'test';     plhControls.Controls.Add(myUserControl ); } 

It crashes inside my CreateChildControls with error : The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases.

The exact line is when I add the webControls to the placeholder inside my UserControl :

plhContent.Controls.Add(myWebControl); 

So I don’t understand why in this case I cannot move a web control inside the CreateChildControls event when I add my UserControl dynamically.

  • 1 1 Answer
  • 1 View
  • 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-11T10:14:46+00:00Added an answer on May 11, 2026 at 10:14 am

    Since LoadControl catch up every event of the loaded control to the current event, it is impossible to run the CreateChildControls at the same time as the parent since the event already occurred ed at that time.

    In my case I cannot add dynamically my UserControl, so I did the opposite to reproduce the same behaviour I wanted. I initialize all my controls, and remove those I don’t want OnClick. This add unneeded load time, but it is acceptable in the scenario I use it.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Apparently you want to create an application that can generate… May 13, 2026 at 1:04 am
  • Editorial Team
    Editorial Team added an answer Refactor your code into smaller work units. Too much conditional… May 13, 2026 at 1:04 am
  • Editorial Team
    Editorial Team added an answer The first step is to really stop the repeated calling… May 13, 2026 at 1:04 am

Related Questions

When I create WPF applications, very quickly my XAML starts to bloat. I then
We are developing large ASP.NET applications with lot of dynmically created pages containing ASCX
I have a UserControl that consists of three TextBoxes. On a form I can
I have a usercontrol that is meant to take up the entire form. I

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.