When Page.OnInit is done and exited, can I be sure that ALL child controls have called OnInit as wel

Discussion in 'ASP .Net' started by Sally, Apr 14, 2004.

  1. Sally

    Sally Guest

    Just confused about when OnInit and Constructor gets called in the
    parent/child case.

    Page.AddParsedSubObject() <- do all the sub's constructors get called
    Page.OnInit() Children.OnInit() (from what I have read, no particular

    So where does CreateChildControls() come in and when
    CreateChildControls() is done, does that mean that all
    Children.OnInit() have been called?
    Sally, Apr 14, 2004
    1. Advertisements

  2. Sally

    bruce barker Guest

    in short no.

    CreateChildControls is deferred for as long as possible. If your control
    does not call EnsureChildControls (say no postback or viewstate handling
    required), then it may not get called until PreRender (well after OnLoad).

    AddParsedSubObject(), is used by the aspx parser to notify your control that
    is parsed a control nested inside yours. your control is supposed to decide
    what to do with this control. you may add it to your controls Controls
    collection right away, or defer until CreateChildControls() is called if

    OnInit is called close to control creation, but there is no control of the
    timing. your controls children may be created first or after. as your
    CreateChildControls() can create new controls on its own, this will not have
    been Init'd yet.

    -- bruce (sqlwork.com)
    bruce barker, Apr 15, 2004
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.