Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > is this a hack?

Reply
Thread Tools

is this a hack?

 
 
foldface@yahoo.co.uk
Guest
Posts: n/a
 
      07-13-2004
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
 
Reply With Quote
 
 
 
 
Kyril Magnos
Guest
Posts: n/a
 
      07-13-2004
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


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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



 
Reply With Quote
 
 
 
 
foldface@yahoo.co.uk
Guest
Posts: n/a
 
      07-14-2004
> Then, events should fire in the proper order.

That is the proper order. The OnInit and Render events occur for the
parent first, see
http://groups.google.co.uk/groups?hl...TF-8%26hl%3Den

The problem is that isn't what I want to occur, I want the child
events to
occur after the parent events.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments