I have googled around for half day searching for the answer but no success. I’m trying my luck here.
My ASP.Net does not have update panel.
I succeed to show progress bar after user click Export to Excel but it never hides back after Respond.End.
Is there any method to solve the problem?
Here’s the codes:
Javascript to show progress bar:
<script type="text/javascript">
function ShowProgress() {
setTimeout(function () {
var modal = $('<div />');
modal.addClass("modal");
$('body').append(modal);
var loading = $(".loading");
loading.show();
var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
loading.css({ top: top, left: left });
}, 200);
}
$('form').live("submit", function () {
ShowProgress();
});
</script>
Code behind (Page Load) :
ClientScript.RegisterStartupScript(Me.[GetType](), "load", "$(document).ready(function () { $('[id*=btnExport]').click(); });", True)
Code behind (Export to Excel) :
Dim style As String = "<style> .text { mso-number-format:'#,##0.000_);[Red](#,##0.000)';text-align:right; } </style> "
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", fName))
HttpContext.Current.Response.ContentType = "application/ms-excel"
HttpContext.Current.Response.ClearContent()
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Unicode
HttpContext.Current.Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble())
HttpContext.Current.Response.Write(style)
Using sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
'To Export all pages
For Each row As GridViewRow In gv.Rows
'For Each cell As TableCell In row.Cells
For i As Integer = 0 To row.Cells.Count - 1
Dim str As String = row.Cells(i).Text
If i > 7 Then
row.Cells(i).Attributes.Add("class", "text")
End If
Next
Next
pnl.RenderControl(hw)
HttpContext.Current.Response.Write(sw.ToString())
End Using
HttpContext.Current.Response.Flush()
HttpContext.Current.Response.SuppressContent = True
HttpContext.Current.ApplicationInstance.CompleteRequest()
Response.[End]()