locked
Button won't postback after long-lasting asyncs RRS feed

  • Question

  • User2115795802 posted

    Hello to all! 

    I faced with a weird situation. Let's first take a look at a simple example in ASP.NET Web Forms:

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                    <asp:Button ID="testButton" runat="server" Text="Run" OnClick="testButton_Click" />
            </ContentTemplate>
        </asp:UpdatePanel>
        <asp:UpdateProgress ID="UpdateProgress1" runat="server">
            <ProgressTemplate>
                Loading...
            </ProgressTemplate>
        </asp:UpdateProgress>
        <asp:UpdatePanel ID="UpdatePanel2" runat="server">
            <ContentTemplate>
                <asp:Label ID="Label1" runat="server"></asp:Label>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="testButton" EventName="Click" />
            </Triggers>
    </asp:UpdatePanel>
     public partial class About : Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected async void testButton_Click(object sender, EventArgs e)
            {
                Task<string>[] List = new Task<string>[]
                {
                    RunLong1(),
                    RunLong2()
                };
    
                string[] responses = await Task.WhenAll(List);
                
                Label1.Text = responses[0] + " " + responses[1];
            }
    
            private async Task<string> RunLong1()
            {
                await Task.Run(() =>
                {
                    System.Threading.Thread.Sleep(100000);
                });
                return "finished the async task 1";
            }
    
            private async Task<string> RunLong2()
            {
                await Task.Run(() =>
                {
                    System.Threading.Thread.Sleep(60000);
                });
                return "finished the async task 1";
            }
    
        }

    So, I have a button inside an update panel linked to an Updateprogress panel. When the button is clicked, the Updateprogress panel is triggered and the word "loading" appears. In addition, the same button is the trigger to another update panel where it posts back a result. When I click the button, two async methods start running in parallel mode. After they finish their tasks, a message is displayed. 

    Here it is the weird thing. If the running time of one of the async methods is more than 100,000 msec, then the button won't post back. The word "loading" stays there forever! If the duration of the async method is less than 100,000 msec, then when I click the button, it runs both RunLong1 & RunLong2 async methods and when all finish, the label1 inside the updatePanel2 displays a text and the word "loading" disappears. 

    Why does this happen? Why won't the button post back if one of the async methods lasts more than 100 sec?

    Friday, November 23, 2018 11:57 PM

Answers

  • User-943250815 posted

    Try set AsyncPostBackTimeout (in seconds) on ScriptMannager in example bellow 10 minutes
    AsyncPostBackTimeout have a default of 90 seconds, after this 90s UpdatePanel forget about return, so you have to adjust for UpdatePanel wait for a return

    <asp:ScriptManager ID="scriptManager" runat="server" AsyncPostBackTimeout="600"></asp:ScriptManager>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 24, 2018 1:15 AM