UpdatePanel postback confusion

Last post 03-02-2007 7:19 AM by R_Edwards. 8 replies.

Sort Posts:

  • UpdatePanel postback confusion

    02-01-2007, 1:01 PM
    • Member
      14 point Member
    • Ian1971
    • Member since 04-28-2005, 12:34 PM
    • London
    • Posts 23

    Hello!

    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).

    Advice appreciated!

    thanks

    Ian 

  • Re: UpdatePanel postback confusion

    02-02-2007, 8:38 AM
    • Member
      23 point Member
    • R_Edwards
    • Member since 01-10-2007, 8:37 AM
    • Bristol, UK
    • Posts 43

    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.

     Rick Edwards 

  • Re: UpdatePanel postback confusion

    02-09-2007, 9:14 AM
    • Member
      14 point Member
    • Ian1971
    • Member since 04-28-2005, 12:34 PM
    • London
    • Posts 23

    No they aren't nested withing each other. They are siblings with the same parent UpdatePanel

     

    Ian
     

  • Re: UpdatePanel postback confusion

    02-09-2007, 10:03 AM
    Answer
    • Member
      46 point Member
    • badgrs
    • Member since 12-14-2006, 4:36 PM
    • Posts 31
    So UseControlB is recieving a post back on the server side but the UpdatePanelB that its inside isn't updating? I'm pretty sure thats what should happen, all controls on the page will be rebuilt and have their page_load functions called whether or not they are inside the UpdatePanel that caused the post back or not. I think....
  • Re: UpdatePanel postback confusion

    02-09-2007, 2:34 PM

    Hi Ian,

    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.

    Regards,

     

    Dennis van de Laar
    http://dennisv.net/

    Don't forget to mark the most helpful reply/replies as Answer.
  • Re: UpdatePanel postback confusion

    02-09-2007, 2:36 PM
    • Member
      637 point Member
    • encapsul2
    • Member since 04-26-2006, 9:10 PM
    • San Francisco
    • Posts 207

    try ensuring that ALL update panels are set to "conditional" and see if that helps.

    cheers

    Matthew


    Performance Outlook
  • Re: UpdatePanel postback confusion

    02-20-2007, 7:12 AM
    • Member
      14 point Member
    • Ian1971
    • Member since 04-28-2005, 12:34 PM
    • London
    • Posts 23

    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?

  • Re: UpdatePanel postback confusion

    02-20-2007, 12:43 PM
    • Contributor
      2,460 point Contributor
    • Steve Marx
    • Member since 05-26-2006, 8:35 PM
    • Microsoft
    • Posts 643

    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.

    Steve Marx | ASP.NET AJAX Evangelist | Microsoft Corporation
  • Re: UpdatePanel postback confusion

    03-02-2007, 7:19 AM
    • Member
      23 point Member
    • R_Edwards
    • Member since 01-10-2007, 8:37 AM
    • Bristol, UK
    • Posts 43

    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.

    Rick Edwards

Page 1 of 1 (9 items)