locked
Controlling multiple update panels RRS feed

  • Question

  • User615288127 posted

    I'm using Visual Studio 2015 with SQL Server 2014, VB.

    I have multiple update panels each with their own control button.  Is there a way I can execute each of them sequentially with one button click?  In other words, run the first, when it is finished automatically run the second, etc.

    I'm hoping someone can point me in the right direction if this is possible.  Thanks in advance!

    Monday, January 22, 2018 5:34 AM

All replies

  • User-1716253493 posted

    I hope this will help you

    https://msdn.microsoft.com/en-us/library/bb398867.aspx

    Monday, January 22, 2018 11:09 AM
  • User615288127 posted

    Thanks for the response.  Not exactly what I'm looking for but still good information.  I'm looking to execute the panels sequentially (finish one before the next one starts), not concurrently.  Hopefully this can be done with one button click rather than a separate click for each panel.

    Monday, January 22, 2018 1:19 PM
  • User61956409 posted

    Hi,

    It seems that you’d like to trigger UpdatePanels update one by one in turn, if that is the case, you can try to trigger another button click event after one click event is finished. The following sample works for me, you can refer to it.

    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <div>
        <h1>current time</h1>
        <%= DateTime.Now%>
        <br />
        <h1>UpdatePanel1</h1>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:Button ID="btn1" runat="server" Text="Button1" OnClick="btn1_Click" />
                <br />
                <br />
                <%= DateTime.Now%>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btn1" EventName="click" />
            </Triggers>
        </asp:UpdatePanel>
        <h1>UpdatePanel2</h1>
        <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:Button ID="btn2" runat="server" Text="Button2" OnClick="btn2_Click" />
                <br />
                <%= DateTime.Now%>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btn2" EventName="click" />
            </Triggers>
        </asp:UpdatePanel>
    </div>
    protected void btn1_Click(object sender, EventArgs e)
    {
        Thread.Sleep(10 * 1000);
    
        string myscript = "document.getElementById('" + btn2.ClientID + "').click()";
        ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "myscript", myscript, true);
    
    }
    
    protected void btn2_Click(object sender, EventArgs e)
    {
        Thread.Sleep(10 * 1000);
    }

    With Regards,

    Fei Han

    Tuesday, January 23, 2018 8:45 AM
  • User615288127 posted

    Hi Fei Han,

    Thanks for the reply but apparently I'm missing something.  Since I'm using VB I had to do some conversion and what I came up with is below.  However, other than loading with the current time nothing appears to happen when either button is clicked.

    ASP side:

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="TestCprog3.aspx.vb" Inherits="TestCprog3" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title></title>
    
    </head>
    <body style="width: 1446px">
    
        <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <div>
        <h1>current time</h1>
        <%= DateTime.Now%>
        <br />
        <h1>UpdatePanel1</h1>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:Button ID="btn1" runat="server" Text="Button1" OnClick="btn1_Click" />
                <br />
                <br />
                <%= DateTime.Now%>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btn1" EventName="click" />
            </Triggers>
        </asp:UpdatePanel>
        <h1>UpdatePanel2</h1>
        <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:Button ID="btn2" runat="server" Text="Button2" OnClick="btn2_Click" />
                <br />
                <%= DateTime.Now%>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btn2" EventName="click" />
            </Triggers>
        </asp:UpdatePanel>
    </div>
        </form>
    </body>
    </html>

    VB code behind:

    Imports System.Threading
    
    Partial Class TestCprog3
        Inherits System.Web.UI.Page
    
        Protected Sub btn1_Click(ByVal sender As Object, ByVal e As EventArgs)
            Thread.Sleep(10 * 1000)
            Dim myscript As String = "document.getElementById('" & btn2.ClientID & "').click()"
            ScriptManager.RegisterClientScriptBlock((TryCast(sender, Control)), Me.[GetType](), "myscript", myscript, True)
        End Sub
    
        Protected Sub btn2_Click(ByVal sender As Object, ByVal e As EventArgs)
            Thread.Sleep(10 * 1000)
        End Sub
    
    End Class

    Please let me know if you see what I'm missing.  Many thanks for your time and effort!

    Tuesday, January 23, 2018 5:01 PM
  • User61956409 posted

    Hi,

    I implement it in VB, which works fine on my side, I will share my sample code, you can try it on your side.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <div>
         <h1>current time</h1>
                <%= DateTime.Now%>
                <br />
                <h1>UpdatePanel1</h1>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <asp:Button ID="btn1" runat="server" Text="Button1" OnClick="btn1_Click" />
                        <br />
                        <br />
                        <%= DateTime.Now%>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="btn1" EventName="click" />
                    </Triggers>
                </asp:UpdatePanel>
                <h1>UpdatePanel2</h1>
                <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <asp:Button ID="btn2" runat="server" Text="Button2" OnClick="btn2_Click" />
                        <br />
                        <%= DateTime.Now%>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="btn2" EventName="click" />
                    </Triggers>
                </asp:UpdatePanel>
        </div>
        </form>
    </body>
    </html>
        Protected Sub btn1_Click(sender As Object, e As EventArgs)
            Thread.Sleep(10 * 1000)
    
            Dim myscript As String
            myscript =  "document.getElementById('" + btn2.ClientID + "').click()"
    
             ScriptManager.RegisterClientScriptBlock( _
                Me, _
                Me.GetType(), _
                "myscript", _
                myscript, _
                True)
        End Sub
    
        Protected Sub btn2_Click(sender As Object, e As EventArgs)
            Thread.Sleep(10 * 1000)
        End Sub

    After page is loaded, i click the Button1, both UpdatePanel1 and UpdatePanel2 will be updated.

    With Regards,

    Fei Han

    Thursday, January 25, 2018 6:09 AM
  • User615288127 posted

    Hi,

    I did a copy/paste of your code and got the same results as before.  The page loads with all 3 time displays the same.  Clicking on either button 1 or button 2 does nothing.  I get the same results in Firefox, Chrome, Edge and the old Explorer.

    Thursday, January 25, 2018 11:26 PM
  • User615288127 posted

    Maybe I need to rephrase the question.  I have Button1 outside of my updatepanels (multiple).  Each updatepanel has a unique Button inside along with an updateprogress.  As there are multiple update panels I would like to have Button1 start a "chain reaction" whereby updatepanel1 (and updateprogress1) executes followed upon completion by updatepanel2, etc.

    Currently each updatepanel (and updateprogress) works fine independently of each other.  It would be nice if the user could just click one button rather then each button separately as the previous panel updates.

    Any ideas or suggestions are welcome.  Thanks in advance for your time!

    Sunday, January 28, 2018 5:02 PM