Avatar of Vic-20
Vic-20
Flag 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>

Button-Frozen1.JPGButton-Frozen2.JPG
ASP.NET

Avatar of undefined
Last Comment
Vic-20

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Roopesh Reddy

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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()."
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck