Hi Poonam123,
Response.End sends all currently buffered output to the client and stops execution of the page.
So you need to do it in new page.
Check this example. Now please take its reference and correct your code.
HTML
<style type="text/css">
.overlay
{
position: fixed;
z-index: 999;
height: 100%;
width: 100%;
top: 0;
background-color: Black;
filter: alpha(opacity=60);
opacity: 0.6;
-moz-opacity: 0.8;
}
</style>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="up11">
<ProgressTemplate>
<div class="overlay">
<div style="z-index: 1000; margin-left: 35%; margin-top: 300px; opacity: 1; -moz-opacity: 1;">
<img alt="" src="loader.gif" />
</div>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="up11" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="downloadformat" runat="server" Text="Download Format" CssClass="btn btn-success"
OnClick="downloadformat_Click" OnClientClick="showProgress()" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="downloadformat" />
</Triggers>
</asp:UpdatePanel>
<script type="text/javascript">
function showProgress() {
var updateProgress = $find("<%= UpdateProgress1.ClientID %>");
window.setTimeout(function () {
updateProgress.set_visible(true);
}, 100);
}
</script>
Code
Default
C#
protected void downloadformat_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, typeof(string), "OpenWindow", "window.open('Download.aspx', null, 'height=700,width=760,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no');", true);
}
VB.Net
Protected Sub downloadformat_Click(ByVal sender As Object, ByVal e As EventArgs)
ScriptManager.RegisterStartupScript(Me, GetType(String), "OpenWindow", "window.open('Download.aspx', null, 'height=700,width=760,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no');", True)
End Sub
Download
C#
protected void Page_Load(object sender, EventArgs e)
{
System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath("~/Uploads/Excel03.xls"));
if (file.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=Excel03.xls");
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/ms-excel";
Response.WriteFile(file.FullName);
Response.Flush();
Response.End();
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim file As System.IO.FileInfo = New System.IO.FileInfo(Server.MapPath("~/Uploads/Excel03.xls"))
If file.Exists Then
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=Excel03.xls")
Response.AddHeader("Content-Length", file.Length.ToString())
Response.ContentType = "application/ms-excel"
Response.WriteFile(file.FullName)
Response.Flush()
Response.End()
End If
End Sub