Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Best practices around "Page_PreRender" and "Page_Load" events (http://www.velocityreviews.com/forums/t524165-best-practices-around-page_prerender-and-page_load-events.html)

Max2006 07-23-2007 04:26 PM

Best practices around "Page_PreRender" and "Page_Load" events
 
Hi,

Are there any best practices or recommendations around using
"Page_PreRender" vs "Page_Load"? We are thinking to completely switch to
Page_PreRender event to handle page's controls initialization requirements.

I went through some asp.net page life cycle documentations (and diagrams)
and it seems that we can safely move all Page_Load codes to Page_PreRender.
Is there any work that we can only do in Page_Load and cannot do it in
Page_PreRender?

A link to an online article would greatly help.

Thank you,
Max



bruce barker 07-23-2007 05:41 PM

Re: Best practices around "Page_PreRender" and "Page_Load" events
 
only if the logic belongs there. the simplified cycle is:

oninit - use to init controls before postback data loaded

onload - after postback data applied to controls

onclick/etc - server events fired

prerender - after server events

render - produce html

general control init should be done in oninit. onload is used if
controls use viewstate (bad practice - should only be done with
intranets) or for postback data handling.


-- bruce (sqlwork.com)


Max2006 wrote:
> Hi,
>
> Are there any best practices or recommendations around using
> "Page_PreRender" vs "Page_Load"? We are thinking to completely switch to
> Page_PreRender event to handle page's controls initialization requirements.
>
> I went through some asp.net page life cycle documentations (and diagrams)
> and it seems that we can safely move all Page_Load codes to Page_PreRender.
> Is there any work that we can only do in Page_Load and cannot do it in
> Page_PreRender?
>
> A link to an online article would greatly help.
>
> Thank you,
> Max
>
>


Walter Wang [MSFT] 07-24-2007 02:36 AM

RE: Best practices around "Page_PreRender" and "Page_Load" events
 
Hi Max,

Besides Bruce's input, here's my thoughts on this:

* Initialization code that runs in first page load (non-postback) is
normally in Page_Load (http://support.microsoft.com/kb/317794)

* Normally you need to register client script in PreRender (<<Developing
Microsoft ASP.NET Server Controls and Components>>, chapter "Client Script
- Related API"; and this also applies when you're using AJAX:
http://weblogs.asp.net/leftslipper/a...00_-Write-cont
rols-compatible-with-UpdatePanel-without-linking-to-the-ASP.NET-AJAX-DLL.asp
x)


Hope this helps.


Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


Walter Wang [MSFT] 07-27-2007 02:55 AM

RE: Best practices around "Page_PreRender" and "Page_Load" events
 
Hi Max,

I'm writing to check the status of this post. Please reply to let us know.
Thanks.


Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


Max2006 07-30-2007 08:07 PM

Re: Best practices around "Page_PreRender" and "Page_Load" events
 
Hi Walter,

Your response helped me; however I was looking for an actual best practices
guidelines. From you post I have a feeling that there is no official
guideline?

Thank you,
Max



"Walter Wang [MSFT]" <wawang@online.microsoft.com> wrote in message
news:qRWgrm$zHHA.4200@TK2MSFTNGHUB02.phx.gbl...
> Hi Max,
>
> I'm writing to check the status of this post. Please reply to let us know.
> Thanks.
>
>
> Regards,
> Walter Wang (wawang@online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
>
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>




ThunderMusic 07-30-2007 10:46 PM

Re: Best practices around "Page_PreRender" and "Page_Load" events
 
Hi
What we usually do here is the following :

/*************/
In Page_Load : We put the initialization for the objects (like the object
holding the logged user's infos) the postback events and pre render will
need. No display related stuff here because it may be changed by the server
events. Actually, we could move almost all the code from here to OnInit, but
we are doing it in Page_Load just to make it all in one place. Actually, the
only reason I see to put this stuff in the Page_Load is if you depend on
data from your page like a hidden field or something (to know where you're
at, like the id of what you are editing)
/*************/
In PreRender : It's like "Ok, I'm in that exact state, so what do I display
and how do I display it?"
/*************/

These are not "official" guidelines, but it works pretty well in all
situations.

I hope it helps

ThunderMusic

"Max2006" <alanalan1@newsgroup.nospam> wrote in message
news:uAounYUzHHA.3908@TK2MSFTNGP05.phx.gbl...
> Hi,
>
> Are there any best practices or recommendations around using
> "Page_PreRender" vs "Page_Load"? We are thinking to completely switch to
> Page_PreRender event to handle page's controls initialization
> requirements.
>
> I went through some asp.net page life cycle documentations (and diagrams)
> and it seems that we can safely move all Page_Load codes to
> Page_PreRender. Is there any work that we can only do in Page_Load and
> cannot do it in Page_PreRender?
>
> A link to an online article would greatly help.
>
> Thank you,
> Max
>




Walter Wang [MSFT] 07-31-2007 04:06 AM

Re: Best practices around "Page_PreRender" and "Page_Load" events
 
Thanks ThunderMusic for the input.

Hi Max,

I think the "official" guidelines are scattered in following places:

* ASP.NET page life cycle
(http://msdn2.microsoft.com/en-us/library/ms178472.aspx)
* Crash courses on creating controls
(http://msdn2.microsoft.com/en-us/library/aa530687.aspx)

Of course, the official documentation on creating controls is already the
best place to look up information:

#Creating Controls
http://msdn2.microsoft.com/en-us/asp.net/aa336658.aspx


Hope this helps.


Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


ThunderMusic 07-31-2007 12:37 PM

Re: Best practices around "Page_PreRender" and "Page_Load" events
 
Hi,
for an ASP.NET Page cycle, we found this page to be REALLY useful when we
developped our controls.
http://weblogs.asp.net/jeff/archive/...04/172683.aspx

I hope it helps

ThunderMusic

"Walter Wang [MSFT]" <wawang@online.microsoft.com> wrote in message
news:1tx9Dhy0HHA.4844@TK2MSFTNGHUB02.phx.gbl...
> Thanks ThunderMusic for the input.
>
> Hi Max,
>
> I think the "official" guidelines are scattered in following places:
>
> * ASP.NET page life cycle
> (http://msdn2.microsoft.com/en-us/library/ms178472.aspx)
> * Crash courses on creating controls
> (http://msdn2.microsoft.com/en-us/library/aa530687.aspx)
>
> Of course, the official documentation on creating controls is already the
> best place to look up information:
>
> #Creating Controls
> http://msdn2.microsoft.com/en-us/asp.net/aa336658.aspx
>
>
> Hope this helps.
>
>
> Regards,
> Walter Wang (wawang@online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
>
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>





All times are GMT. The time now is 01:20 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57