Showing posts with label ASP.NET Page Life Cycle. Show all posts
Showing posts with label ASP.NET Page Life Cycle. Show all posts

ASP.NET Page Life Cycle, event order, master page, page and control events order


    PAGE: Page.OnPreInit()
        USER CONTROL: UserControl.OnInit()
MASTER PAGE: MasterPage.OnInit()
    PAGE: Page.OnInit()
    PAGE: Page.OnInitComplete()
    PAGE: Page.OnLoad()
MASTER PAGE: MasterPage.OnLoad()
        USER CONTROL: UserControl.OnLoad()
    PAGE: Page.OnLoadComplete()
           Page Event Handlers
    PAGE: Page.OnPreRender()
MASTER PAGE: MasterPage.OnPreRender()
        USER CONTROL: UserControl.OnPreRender()
    PAGE: Page.OnPreRenderComplete()
    PAGE: Page.OnSaveStateComplete()
        USER CONTROL: UserControl.OnUnload()
MASTER PAGE: MasterPage.OnUnload()
     PAGE: Page.OnUnload()

More information here:
ASP.NET Page Life Cycle

How to maintain the view state of dynamically added control in an asp.net page

First of all you must read these articles:

The viewstate of a dynamically added control can be saved for maintaining the state of the control after postback.
This can be achieved by adding the controls before the Load Viewstate stage (see the page stages in the articles above). Therefore the viewstate information ( control value) from the request will be applied to already added controls as they are defined already in the page.
The right place of adding dynamic controls is Page_Init. Use Page_Init also for defining dynamically master pages and themes.