views:

46

answers:

2

Hi everyone, I need some guidelines about building the code behind of my pages correctly. I mean, I'm building in asp.net for a year now, and mostly using the Page_Load event. (and ofcourse "event handling" the events triggered by the user's actions). I know about the page life cycle and the order of events that happens when a page is requested etc.. . Is it normal that, generally, in a data-driven page, for example, I'm not using any of the "pre_render", "page_unload", "pre_init" etc.. event handlers? or am I missing something here? any guidelines would help me a lot, including links or whatever you think that would instruct me well. thanks.

+4  A: 

You are not missing anything.

Most asp.net code does not use these events, and you should only be using the handlers if you need to.

For example - if you really need to change the output of the page after all control event handlers (for example button clicks) have fired, use the pre_render event. In my experience this is a rare thing to need.

Many of the event are there just in case you need them.

Oded
1. thanks 2. pre_init happens after the the control event handlers were fired???
Hagai
@Hagai - My bad. I meant `pre_render`, not `pre_init`.
Oded
+1  A: 

Page_Load actually is the most used event handler in page life cycle. What i've used relatively often is Page_Init when i added controls dynamically to the page(ViewState issue).

Look here for further informations: http://www.csharper.net/blog/page_lifecycle_methods_in_asp_net_2_0.aspx

Tim Schmelter