troubleshooting Question

ASP UpdatePanels not working together

Avatar of Vic-20
Vic-20Flag for Australia asked on
ASP.NET
2 Comments1 Solution619 ViewsLast Modified:
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>

Button-Frozen1.JPGButton-Frozen2.JPG
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros