By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 1,905 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Jun 2 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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)
"Beavis" <mu**********@gmail.com> wrote in message
news:11*********************@g10g2000cwb.googlegro ups.com...
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

Jun 2 '06 #2

P: n/a
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

Jun 5 '06 #3

P: n/a
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

Jun 5 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.