0

I'm a newbie to ASP.Net, so my question might be a little bit dumb, I don't quite understand how each stage works in ASP.Net page life cycle, I wrote some code includes a simple page with a label control and a button control on it and found the sequence is :

1.Page initialization event handled.

2.Page load event handled.

3.Page prerender event handled.

4.Page load event handled.

5.Page postback event handled.

6.Button click event handled.

7.Page prerender event handled.

My questions are:

  1. Why some events like page load are raised twice?

  2. People usually said page_load event happens before button click event. I don't quite get it, do people mean page_load event is handled before button click event? if yes then I understand, so is it just something like when we click a submit button, we actually fire 2 events, one for button click event, and one for page load event and page load event is handled first?

  3. Can anyone put these stages in a simple way to explain how each stage steps in? like when a user clicks a button, what's happening behind the scene

1

1 Answer 1

1
  1. Why some events like page load are raised twice?

    The PageLoad event is raised once per page request from the server. When an asp.net page is posted back to the server, it's PageLoad event will be called again. If you check your IIS logs, you should see two requests for the page from your browser/client. The first will be the original request for the page, and the second one will be after your button press (which I assume is causing the post back).

  2. People usually said page_load event happens before button click event. I don't quite get it, do people mean page_load event is handled before button click event? if yes then I understand, so is it just something like when we click a submit button, we actually fire 2 events, one for button click event, and one for page load event and page load event is handled first?

    In the lifetime of you an asp.net page, it begins when a client requests the page, and ends after the page is rendered to the client. The link sent to you by Andrew Shepherd provides a very good tutorial on the asp.net page life cycle. Be sure you read this and understand it.

  3. Can anyone put these stages in a simple way to explain how each stage steps in? like when a user clicks a button, what's happening behind the scene?

    It really depends on what you've got wired up to the button. The button could cause client-side scripting to execute, or it could cause some action to take place on the web server.

Sign up to request clarification or add additional context in comments.

1 Comment

For question 2, I found the article a little hard for me, so I just want to know is my understanding that when clicking a submit button, actually 2 events are fired, one for button click event, and one for page load event and page load event is handled first, if this is correct then I can have a general idea and then start to dig the article further