I've may have misunderstood how AJAX works - Can someone shed some light on the following simplified scenario:
I have a asp.net web application. On a page there is a user control inside an update panel (with no properties changed) and a script manager.
In the user control and on the form there is the a label, both get their text set to DateTime.Now.ToString
in the load event. There is also a button, which causes a post back in the user control.
When I click the button, as I expect the label inside the user control updates and the one label on the page does now. So far so good.
However... the page load event on the page does get processed with isPostBack = True (which I did not expect), and it looks like whatever happens in the load event doesn't get pushed back to the client (as the label didn't update).
I didn't expect the page load event (in the page that contains the user control) to be raised and processed when an AJAX panel is updated, is this correct? or am I doing something wrong? I remember reading something about Page.IsCallback, but that is false, so maybe that has nothing to do with this.
Well, this question is isn't about AJAX per-se, but about Microsoft's AJAX-based UpdatePanel, which is a complex beast. The simple explanation of the way UpdatePanel's work is that everything works the same as a normal full-page "post back" (ViewState POSTed to the server, server-side DOM is recreated, all of the page event life-cycle events are executed) except at the very end the response rendered to the client only includes the subset of HTML needed to refresh the content of the UpdatePanel from which the AJAX request was initiated. There are some additional subtleties and complexities at play, but this is the basic idea.
All of the page lifecycle events get executed even on partial postbacks. You can differentiate between a full postback and a partial postback by doing the following:
if (ScriptManager.GetCurrent(this).IsInAsyncPostBack)
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With