Re: About Control.OnInit

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bruce barker

    Re: About Control.OnInit

    while OnInit is fine, the proper place is the CreateChildCont rols method.

    -- bruce (sqlwork.com)


    Richard Coltrane wrote:
    Hi,
    >
    Last night I had a problem with a nested user control. UCA is declaratively
    nested in UCB, with UCB dynamically loaded (page.loadcontr ol) into PageX. My
    problem was i couldn't read the values of UCA controls from with UCA on
    postback.... although i could from UCB. I thought that was weird if anything
    I was have thought it would be the other way around. Anyway......
    >
    I sorted this out by changing where I dynamically load UCB..... now i do it
    in the OnInit event of the page not OnLoad and now all is cool.... perhaps i
    should have been doing that all along ;)
    >
    So I am reading the docs about the OnInt event and it says:
    >
    "In this stage of the server control's lifecycle, the control's view state
    has yet to be populated. Additionally, you can not access other server
    controls when this method is called either, regardless of whether it is a
    child or parent to this control. Other server controls are not certain to be
    created and ready for access."
    >
    So if this is the case how can i :
    >
    this.pnlTest.Co ntrols.Add(Page .LoadControl("/Views/test.ascx"));
    >
    If, as the docs say, i cant access other server controls, then how come i
    can add child controls to pnlTest, a server control... is this just a
    fluke??? Can this be relied upon to *always* work.
    >
    Thanks
    >
    >
    >
    >
Working...