AJAX postback and page lifecycle

Can someone explain to me how this works.

I have a page that has a button inside an update bar and some class member (_pageContext). This is not a static member, by the way This is his ad

    internal PageContext _pageContext = null;

      

When I click the button, the following events appear (I trace them by making breakpoints)

1) Page constructor. _pageContext == null at breakpoint, ok 2) OnInit (). This is where strange things begin. _pageContext has already been initialized (although its initialization method is also stopped and this breakpoint has never been hit).

How can this happen and where a new instance of the page class can know this _pageContext even though it has never been initialized? It makes sense that the previous instance of the class is restored on a partial On_Init postback, although this is not possible since HTTP is statusless and the browser has no communication with instances of the server class.

Any suggestions and explanations for this supernatural fact?

0


a source to share


1 answer


HTTP is truly stateless. ASP.NET WebForms abstracts that away from you with a clever use of ViewState. It looks like the pageContext is in ViewStated - see this for more information .



And don't worry if it's not obvious at first - understanding the life cycle is tricky. Nope.

0


a source







All Articles