Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update Panel PostBackTrigger, Update Progress not displaying

I have an update panel and update progress with a PostBackTrigger Event. But update progress is not showing when i am clicking on the button. please find the below sample code

<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="updatepanelDropDownTaskType" CssClass="Token-setup-popup" DynamicLayout="true">
    <ProgressTemplate>
        <div id="loading" class="loading">
            <asp:Image runat="server" ID="imgBusyIndicator" ImageUrl="~/images/busy-indicator.gif" />
        </div>
    </ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="updatepanelDropDownTaskType" runat="server" UpdateMode="Conditional"> 
    <Triggers>
        <asp:PostBackTrigger ControlID="btnExport" />
    </Triggers>
    <ContentTemplate>     
            <asp:Button ID="btnExport" runat="server" Text="Export To CSV"  CssClass="button" CausesValidation="true" onclick="btnExport_Click" ClientIDMode="Static"/></asp:Button>
    </ContentTemplate>
</asp:UpdatePanel>

My code behind

HttpResponse Response = System.Web.HttpContext.Current.Response;
        Response.ClearHeaders();
        Response.AppendHeader("Content-Disposition", "attachment; filename=" + FileName);
        Response.ContentType = FileType;
        Response.Write(content);
        HttpContext.Current.ApplicationInstance.CompleteRequest();
like image 746
Bhuvan Avatar asked Mar 05 '14 07:03

Bhuvan


1 Answers

Well Your code is Okay. Problem is with your Triggers which you are using in UpdatePanel.

Microsoft says

The UpdateProgress control renders a <div> element that is displayed or hidden depending on whether an associated UpdatePanel control has caused an asynchronous postback. For initial page rendering and for synchronous postbacks, the UpdateProgress control is not displayed.

See more details on MSDN

So you are using PostBackTrigger in your UpdatePanel which will cause a synchronous postback and UpdateProgress will not show up .

<Triggers>
    <asp:PostBackTrigger ControlID="btnExport" />
    // Incorrect
</Triggers>

Change it to

<Triggers>
    <asp:AsyncPostBackTrigger ControlID="btnExport" />
    // Correct
</Triggers>

And this will show up your UpdateProgress and will work as you are expecting.

As you have mentioned in your comments you are performing downloading as well on your Grid. Same way you could register your Button with ScriptManager. This will register your button and will aware of download button while asynchronous postbacks.

 protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
 {    
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         Button btnExport = e.item.FindControl("btnExport") as Button;
         if (btnExport != null)
         {
             ((ScriptManager)this.Page.Master.FindControl("ID of your Script manager")).RegisterPostBackControl(downloadDocColumn);
             // In Above line i assumed Script Manager is placed on Your master page.
         }
     }
  }

Hope this helps...

like image 198
Mayank Pathak Avatar answered Nov 16 '22 02:11

Mayank Pathak