Repost, please help, my composite control's oninit won't fire

B

Beavis

I hate to repost a message, but I am still at the same point where I
was when I originally posted, and hopefully someone else will see this
one...

Ok, so I have gone off and documented the lifecycle of a page with a
custom composite control on it. You can find that document here:


http://www.ats-engineers.com/lifecycle.htm


Now, I am working on a much more complex grid example, and according to

my findings, the order should be like so:


Page Constructor
Page OnInit
Page OnLoad Enter
Page Instantiates Composite Control
Control Constructor Enter
Control Adds Button
Control Constructor Exit
Control OnInit
Page OnLoad Exit
Control OnLoad
Page PreRender
Page SaveViewState
Control SaveViewState
Control OnUnLoad
Page OnUnLoad


The document I linked to above shows the code that I used to produce
this output, and I have stepped through it multiple times to verify
that this order is true.


Now my problem is that in my MUCH more complex Custom Control, I watch
the code go from the controls constructor, to the pages OnPreRender
method, skipping the controls oninit and onload methods (which will
skip the LoadViewState method if it is a postback). There has gotta be
something simple wrong with my other composite control. However that
control is about 700 lines of code, and I don't expect anyone to go
through it, especially considering that it uses about 10 other custom
classes that I wrote.


So without me getting into too much detai, the question is what could
cause a controls oninit to not fire. This composite control inherits
from PlaceHolder, just like the example I site in my page I referred to

above, so that shouldn't be the problem. The control is being added to
the page just as in the above example as well. However, I am trying to
get it to load the view state, and those methods are never called
either, it's like it isn't a System.Web.Control at all...


Any ideas?



Andy Baldwin
 
B

bruce barker \(sqlwork.com\)

control onint does not always fire on page init. it will only be included if
it exits at page init time. if you create your child controls at prerender,
then the child controls onint fires during prerender.

the LoadViewState and LoadPostback event occur between Pages OnInit and
OnLoad events. They recursively walk the control tree to fire the events.
Your control and its children must exist after onit fire, for them to
receive the LoadViewState and LoadPostbackData events.

if you want your custom controls children to handle postback and viewstate
data, then you should create them in the CreateChildControls overload and
call EnsureChildControls in your OnInit.

-- bruce (sqlwork.com)
 
B

Beavis

Good to know, thank you for your answer, I understand the question was
a bit convoluted :D

Thanks again, i will try that out and let you know my findings

AB
 
B

Beavis

Ok, so that helped a lot, the problem was that I wasn't actually adding
the control to the page, rightfully so, I wanted some other things to
get checked out and fiddled with before it was actually generated.
Adding the grid control un initialized though worked... kinda hard to
explain, but thanks you got me on the right track!

Thanks again

AB
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top