is this a hack?

F

foldface

Hi
I commonly have the problem that given a page with 2+ usercontrols
many of the pages events occur before the childs, e.g. PageLoad, because
of this I wind up moving code from PageLoad to PreRender. This doesn't
feel right.

More info:
(1) I put code in Page_Load in the usercontrols so that all the ViewState
and other stuff has loaded in
(2) I put code in PreRender in the parent because of this
(3) Given a page with a usercontrol(1) which itself holds a UserControl(2) then
as the PreRender for the UserControl happens second then I could wind up
with Control2 having code in PageLoad, Control1 having code in PreRender
and the page having code in Render to ensure the right loading order

To get around this I've though of making a class that takes as arguments
a number of events, e.g. the Page_Loads of the child UserControls,
and once all of these have fired it calls some other event,
e.g. Page_Load2, of the parent.
This feels like a solution that will work but possibly still not
the best way of doing things. The page itself could also do this
but thats more of less the same thing.

Any feedback? Are there any asp.net patterns about the place?

Ta
F
 
K

Kyril Magnos

Well, you are correct about it not feeling right. You need to examine how
you are reloading your controls when a postback occurs. First off, make sure
that you are checking to see if this is a postback using Page.IsPostBack.
Secondly, you need to reload your controls in EXACTLY the same order,
everytime, so that the ASP.NET runtime can recreate the control tree
accurately. Then, events should fire in the proper order.

HTH,

Kyril
 

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

Top