ASP.NET Session and Page Life Cycle -


Assume that I have the page loaded in an asp.net .aspx page Method and another method for one button click event.

In the page load method I am checking that the user is logged in by checking the session. Whether it is or not, I am storing results in a global variable.

  Boolean isGuest = false; Secure Zero Page_load (object sender, eventAgps E) {if (session ("id") == empty) isGuest = true; Else isGuest = false; }  

Let's say that 20 minutes have passed, and I do not know whether the session has ended or not, and then I click on a button, the event would have happened this way Is:

  Protected Zero Button_Click (Object Sender, EventArgs E) {If (isGuest == is wrong) // Something else is / one more thing}  

My question is: when I click the button, ASP.NET passes through the Page_Load method again (check isGuest ) or It only Button_Cl Ick means the method, it uses the boolean isGuest which can be a false , but in fact the session has ended, this means Should be true .

Page_load triggers always before Goes control events

Take a look:

Side-note: If you only want to work on the first load and do not check the IsPostBack property on each postback Will be.


Comments