Last post Mar 02, 2007 11:19 AM by R_Edwards
Feb 01, 2007 05:01 PM|Ian1971|LINK
I have a page with a user control (UserControlA), which itself contains some content and another usercontrol (UserControlB) nested inside.
The content in the UserControlA is within an update panel (UpdatePanelA) and contains two buttons (ButtonA1, ButtonA2)
UserControlB is within an update Panel (UpdatePanelB) with UpdateMode="Conditional" and the trigger set to the ButtonA1 so my expectation is that when ButtonA1 is clicked then UserControlB is posted back and the UpdatePanelB display updated. Which is what
happens. Good so far
The problem is that I am also getting a postback in UserControlB when ButtonA2 is clicked and this isn't a trigger. UpdatePanelB is not updated though in this case.
Is this the way it is supposed to behave? or am I doing something wrong? I don't want to be doing a load of unnecessary work loading UserControlB when any button is clicked (even though the display isn't updated).
Usercontrols UpdatePanel Postback
Feb 02, 2007 12:38 PM|R_Edwards|LINK
Are your update panels nested? In which case a postback event in the parent that triggers an update will trigger a parent update AND a child update, whereas a postback update in the child won't update the parent by default.
Feb 09, 2007 01:14 PM|Ian1971|LINK
No they aren't nested withing each other. They are siblings with the same parent UpdatePanel
Feb 09, 2007 02:03 PM|badgrs|LINK
Feb 09, 2007 06:34 PM|Dennis van de Laar|LINK
Try to set the Updatemode of the UpdatePanelA also to conditional. Maybe you can avoid this to specifically define ButtonA2 as a trigger for UpdatePanelA. Make sure that this trigger is an async trigger and not a postback trigger. Hope this hepls.
Feb 09, 2007 06:36 PM|encapsul2|LINK
try ensuring that ALL update panels are set to "conditional" and see if that helps.
Feb 20, 2007 11:12 AM|Ian1971|LINK
Thanks for all your suggestions. Sorry for the delay replying.
From my tests I believe badgrs is correct and the Page_Load for all controls on the page will be fired regardless of whether they are inside an UpdatePanel or not. If they aren't inside an UpdatePanel that is being updated then their IsPostback value will
be false, true if they are being updated. This seems to me to be by design, and probably so that the full page state is posted back and to allow all controls the chance to play a part in the postback even if they aren't being updated themselves.
e.g. I have a date selector user control in which the user has entered a date. I also have a button that causes an update panel to read the value from this control and display it in a TextBox. If the button is pressed then the value entered in the date control
will be sent back to the server and the date control can expose this value to its hosts - even though the date control itselt isn't being "posted back" in terms of an Asp.Net postback (i.e. IsPostback = false). This means that the code behind for the button
can read the date entered and put it in the TextBox in the UpdatePanel
Does that sound right to you?
Feb 20, 2007 04:43 PM|Steve Marx|LINK
That sounds mostly correct.
An UpdatePanel async postback is, for all intents and purposes, the same as a regular postback on the server. That means all the controls will go through their normal lifecycle (including load, init, prerender, etc.) regardless of where they are
on the page. Page.IsPostBack should be equal to true throughout, since the page is in a postback.
Mar 02, 2007 11:19 AM|R_Edwards|LINK
Yep that sounds correct. The Control tree is rebuilt on postback whether its an AJAX type call or otherwise and the control lifecycle followed for each control accordingly (page_load, prerender, etc). Microsoft AJAX with respect to postback is not strictly
asynchronous (AFAIK) but rather only refreshes the region of the page defined in the update panel, the actual request - response cycle occurs as normal but because only part of the page is refreshed it creates the illusion of an asynchronous process.