locked
Update progress bar not working with postbacktrigger RRS feed

  • Question

  • User2103449440 posted

    I have update progress in master page which shows the loader whenever the content page is refreshed or on postback but on my content page everything is working fine execpt for the download button where the loader does not get disabled when clicked.

    this is the master page:

        <div class="container-fluid" id="body">
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:ContentPlaceHolder ID="BodyContentPlaceHolder" runat="server">
                    </asp:ContentPlaceHolder>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="menuBar" />
                    <asp:AsyncPostBackTrigger ControlID="MenuCategories" />
                </Triggers>
            </asp:UpdatePanel>

            <asp:UpdateProgress ID="progress" runat="server" DynamicLayout="true" DisplayAfter="0">
                <ProgressTemplate>
                    <div class="ui-widget-overlay">
                        <div id="dvLoading">
                        </div>
                    </div>
                </ProgressTemplate>
            </asp:UpdateProgress>
        </div>
        <script type="text/javascript">
            var updateProgress = null;
            function postbackButtonClick() {
                updateProgress = $find("<%= progress.ClientID %>");
                window.setTimeout("updateProgress.set_visible(true)", updateProgress.get_displayAfter());
                return true;
            }
        </script>


    this is my content page:

        <asp:Content ID="Content2" ContentPlaceHolderID="BodyContentPlaceHolder" runat="Server">
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                 <table style="float: right;">
                    <tr>
                        <td class="Asplabel"><b>No of Records:</b></td>
                        <td>
                            <asp:Label ID="lblRecordsCount" runat="server" Text="" CssClass="Asplabel" Font-Bold="true"></asp:Label>
                        </td>
                        <td>
                                <asp:LinkButton ID="BtnDownload" ClientIDMode="Static" OnClientClick="return postbackButtonClick();" runat="server" Enabled="true" ToolTip="Download Files" CssClass="btn" style="color: #0089d0;" OnClick="BtnDownload_Click">
                                <i class="fa fa-download"></i>
                                </asp:LinkButton>
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
            <Triggers>
                <asp:PostBackTrigger ControlID="BtnDownload"/>
            </Triggers>
            </asp:UpdatePanel>
        </asp:Content>

    On page load loader is working fine and also for other controls where postback occurs except for the download button the loader shows up but does not fade away 
    How should i set the visibilty false for the download button after the pasotback occurs?

    Thursday, July 27, 2017 11:42 AM

Answers

  • User-335504541 posted

    Hi akjain907,

    The reason of the loader no disappear is that a HTTP request can only have one response.

    After you download a file, the page will not get another response.

    So the loader still shows .

    If you still want to use a UpdateProgress, I think you could try to use the button to open a new window to download the file.

    For example:

    In button click event:

     protected void BtnDownload_Click(object sender, EventArgs e)
            {
                string s = "window.open('Download.aspx ', 'Download', 'width=300,height=100,left=100,top=100,resizable=yes');";
                ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);
    
            }

    In download.aspx behind code:

      protected void Page_Load(object sender, EventArgs e)
            {
                System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
                response.ClearContent();
                response.Clear();
                response.ContentType = "text/plain";
                response.AddHeader("Content-Disposition",
                                   "attachment; filename= 123.txt ;");
                response.TransmitFile(Server.MapPath("123.txt"));
                response.Flush();
                response.End();
            }

    Best Regards,

    Billy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 28, 2017 8:43 AM

All replies

  • User-335504541 posted

    Hi akjain907,

    Do you want to hide the linkbutton when the UpdateProgress show?

    If so, I think you could try to hide the link in postbackButtonClick event.

    For example:

      <asp:LinkButton ID="BtnDownload" ClientIDMode="Static"
                                OnClientClick="return postbackButtonClick(this);" runat="server"
                                Enabled="true" ToolTip="Download Files" CssClass="btn"
                                Style="color: #0089d0;" OnClick="BtnDownload_Click">
                                link<i class="fa fa-download"></i>
                            </asp:LinkButton>
            function postbackButtonClick(x) {
                x.style.visibility = "hidden";
                updateProgress = $find("<%= progress.ClientID %>");
                window.setTimeout("updateProgress.set_visible(true)", updateProgress.get_displayAfter());
                return true;
            }

    When I test,I set System.Threading.Thread.Sleep(5000); in behind code.
    And the result is:

    Best Regards,

    Billy

    Friday, July 28, 2017 6:21 AM
  • User2103449440 posted

    No i dont want to hide link button, I want to hide loader because after clicking on linkbutton the loader shows up but does not stop after the file is being downloaded.

    Thank you foe your help.

    Friday, July 28, 2017 6:42 AM
  • User-335504541 posted

    Hi akjain907,

    The reason of the loader no disappear is that a HTTP request can only have one response.

    After you download a file, the page will not get another response.

    So the loader still shows .

    If you still want to use a UpdateProgress, I think you could try to use the button to open a new window to download the file.

    For example:

    In button click event:

     protected void BtnDownload_Click(object sender, EventArgs e)
            {
                string s = "window.open('Download.aspx ', 'Download', 'width=300,height=100,left=100,top=100,resizable=yes');";
                ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);
    
            }

    In download.aspx behind code:

      protected void Page_Load(object sender, EventArgs e)
            {
                System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
                response.ClearContent();
                response.Clear();
                response.ContentType = "text/plain";
                response.AddHeader("Content-Disposition",
                                   "attachment; filename= 123.txt ;");
                response.TransmitFile(Server.MapPath("123.txt"));
                response.Flush();
                response.End();
            }

    Best Regards,

    Billy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 28, 2017 8:43 AM
  • User2103449440 posted

    Thank you for your effort and can you help to answer this question- https://stackoverflow.com/questions/45213246/how-to-show-modal-popup-with-yes-and-no-button-inside-loop-in-asp-net?noredirect=1#comment77403347_45213246

    Friday, July 28, 2017 10:10 AM