Link to home
Start Free TrialLog in
Avatar of Vic-20
Vic-20Flag for Australia

asked on

ASP UpdatePanels not working together

Hi

I'm trying to test a simple example of 2 UpdatePanels with each posting back to the server for some "long operation" and updating the content of their respective label with a result. Basically, 2 async calls, each returning when done. Note I don't want to use Callbacks so please don’t suggest that. I want the UpdatePanel Model to work.

So, clicking both buttons has the problem that only the 2nd pressed button works and the 1st button is never updated. The code-behind can we traced and is clearly calling "UP1.Update()" but no update is shown in the browser. When button 2's update is called then UpdatePanel2 will update but UpdatePanel1 will remain frozen. This is the same if i reverse the order of pressing the buttons.

Basically, the 2nd press of either button is disrupting the update of the first such that it appears to never return for the first button pressed.

Thanks.
Mike


Code-behind
--------------------
public partial class _Default : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {    
  }
 
  protected void btCalcDo_Click(object sender, EventArgs e)
  {
       Thread.Sleep(2000);
       LabelCounter.Text = DateTime.Now.ToString();
       UP1.Update();
  }

protected void Button2_Click(object sender, EventArgs e)
{
      Thread.Sleep(4000);
      LabelCounter2.Text = DateTime.Now.ToString();
      UP2.Update();
}
}



ASP
------

<head runat="server">
  <title></title>
  <script type="text/javascript">
    function DoRefresh(pVisualButton, pActionButton) {
      var VisualButton = document.getElementById(pVisualButton);
      VisualButton.disabled = true;
      var ActionButton = document.getElementById(pActionButton);
      ActionButton.click();
    }
  </script>
</head>
<body>
  <form id="form1" runat="server">
      <asp:ScriptManager ID="ScriptManager1" runat="server">
      </asp:ScriptManager>
      <asp:UpdatePanel runat="server" ID="UP1" UpdateMode="Conditional"
        ChildrenAsTriggers="False">
        <ContentTemplate>
          <div>
            <asp:Button ID="btCalc" runat="server" Text="Button" OnClientClick="DoRefresh('btCalc', 'btCalcDo'); return false;"
              Style="text-align: center" />
            <asp:Label ID="LabelCounter" runat="server" Text="Label" Style="text-align: center"></asp:Label>
            <asp:Button ID="btCalcDo" runat="server" OnClick="btCalcDo_Click" Style="visibility: hidden"
              Height="0px" Width="0px" />
          </div>
        </ContentTemplate>
      </asp:UpdatePanel>
      <asp:UpdatePanel ID="UP2" runat="server" UpdateMode="Conditional"
        ChildrenAsTriggers="False">
        <ContentTemplate>
          <div>
            <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="DoRefresh('Button1', 'Button2'); return false;"
              Style="text-align: center" />
            <asp:Label ID="LabelCounter2" runat="server" Text="Label" Style="text-align: center"></asp:Label>
            <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Style="visibility: hidden"
              Height="0px" Width="0px" />
          </div>
        </ContentTemplate>
      </asp:UpdatePanel>

  </form>
</body>

User generated imageUser generated image
ASKER CERTIFIED SOLUTION
Avatar of Roopesh Reddy
Roopesh Reddy
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Vic-20

ASKER

Ok, at least I know I'm not doing something wrong. The StackOverflow link was very well explained! Thanks for that.

Looks like I'll have to do 2 Callbacks then. Question is can the server call update an UpdatePanel from the Server with the same "UP1.Update()."