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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:35:04+00:00 2026-05-13T23:35:04+00:00

My original understanding was that the asp.net page lifecycle is run once for all

  • 0

My original understanding was that the asp.net page lifecycle is run once for all pages and controls under normal circumstances. When I attached a control during a container’s OnPreRender, I encountered a situation where the control’s OnInit was not called. OK, I considered that a bug in my code and fixed as such, by attaching the control earlier.

But just today, I encountered a situation where OnInit for a control seems to be called after the normal OnInit has been done for everyone else. See stack below. It seems that during the page’s PreRender, the control’s OnInit is called as it is being dynamically added.

So I just want to confirm exactly what ASP.NET’s behavior is? Does it actually keep track of the stage of each control’s lifecycle, and upon adding a new control, it will run from the very beginning?

[HttpException (0x80004005): The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases.]
System.Web.UI.ControlCollection.Add(Control child) +8678663
MyCompany.Web.Controls.SetStartPageWrapper.Initialize()
MyCompany.Web.Controls.SetStartPageWrapper.OnInit(EventArgs e)
System.Web.UI.Control.InitRecursive(Control namingContainer) +333
System.Web.UI.Control.InitRecursive(Control namingContainer) +210
System.Web.UI.Control.AddedControl(Control control, Int32 index) +198
System.Web.UI.ControlCollection.Add(Control child) +80
MyCompany.Web.Controls.PageHeader.OnPreRender(EventArgs e) in
System.Web.UI.Control.PreRenderRecursiveInternal() +80
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842

  • 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-13T23:35:04+00:00Added an answer on May 13, 2026 at 11:35 pm

    A control’s OnInit is called as soon as it’s added to the control tree. In your stack you can see this happening, this occurs:

    System.Web.UI.Control.AddedControl(Control control, Int32 index) +198   
    System.Web.UI.ControlCollection.Add(Control child) +80 
    

    Then this is triggered:

    MyCompany.Web.Controls.SetStartPageWrapper.OnInit(EventArgs e) 
    

    So at whatever point in the lifecycle it’s added, it’s OnInit kicks off.

    Egghead has a good image depicting normal event lifecycles between pages and controls, but just keep in mind that something can’t be executing events if it doesn’t exist yet…if it’s just added, it has to catch up on events at that point instead of when they would have happened if the controls were in markup or CreateChildControls.

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

Sidebar

Related Questions

I work on a web-application that is written in C#/ASP.NET. The original framers of
I am using Telerik ASP.Net Ajax controls (theoretically shouldn't matter who makes the 3rd
I am maintaining an ASP.NET MVC project. In the project the original developer has
My understanding is that the original incarnation of JDO required the use of XML
Understanding the difference between throw ex and throw , why is the original StackTrace
original string is a,d,k I want to remove all , and make it to
ORIGINAL (see UPDATED QUESTION below) I am designing a new laboratory database that tests
Original Question: i read that for RESTful websites. it is not good to use
Original Problem: I have 3 boxes each containing 200 coins, given that there is
I have inherited an ASP.net 2.0 VB project and have been given a list

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.