Hi dharmendr, thanks again for you quick reply and your help.
I used your 3rd option (Show Progress Bar when uploading files using AJAX UpdateProgress in ASP.Net) and its working very good.
When i click on the button Export, i get a little loader next to it and once the file is ready, i get the explorer window for save as or open.
But the loader image is still there. Did I forget to put something after the export is finish ?
Javascript:
$(function () {
window.onsubmit = submitAction;
});
function submitAction() {
var updateProgress = $find("<%= UpdateProgress1.ClientID %>");
window.setTimeout(function () {
updateProgress.set_visible(true);
}, 100);
}
HTML
<table>
<tr>
<td>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div style="margin-bottom:1%">
<asp:Button ID="btnExport" CssClass="btn btn-primary" Text="Export to Excel" OnClick="ExportExcel" runat="server" />
<asp:Button ID="btnClose" CssClass="btn btn-primary" Text="Close" OnClientClick="window.close();return false;" runat="server"/>
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnExport" />
</Triggers>
</asp:UpdatePanel>
</td>
<td> </td>
<td>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<img id="export_loader" src="images/ajax-loader.gif" alt="Exporting..."/>
</ProgressTemplate>
</asp:UpdateProgress>
</td>
</tr>
</table>
VB
Protected Sub ExportExcel(ByVal sender As Object, ByVal e As EventArgs)
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand(Session("Query"))
Using sda As New SqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Dim dt As New DataTable()
sda.Fill(dt)
Using wb As New XLWorkbook()
wb.Worksheets.Add(dt, "Output")
dt = Nothing
Response.Clear()
Response.Buffer = True
Response.Charset = ""
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AddHeader("content-disposition", "attachment;filename=" + User.Identity.Name + "_" + DateTime.Now.ToString("yyyymmdd_hhmmss") + ".xlsx")
Using MyMemoryStream As New MemoryStream()
wb.SaveAs(MyMemoryStream)
MyMemoryStream.WriteTo(Response.OutputStream)
Response.Flush()
Response.End()
End Using
End Using
End Using
End Using
End Using
End Sub