Try this
Create an
iframe
in
form1
<form id="form1" runat="server">
<iframe id="iframe1" src="" runat="server" style="visibility:hidden"></iframe></form>
Change your button click event as below
protected void btnExport_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gvEmpdetails.AllowPaging = false;
BindGrid();
for (int i = 0; i < gvEmpdetails.HeaderRow.Cells.Count; i++)
gvEmpdetails.HeaderRow.Cells[i].Style.Add("background-color", "#df5015");
gvEmpdetails.RenderControl(htw);
Session["ResponseData"] = sw.ToString();
iframe.Attributes.Add("src","Download.aspx");
}
Add this script
<script type="text/javascript">
$(function () {
var loading = $(".loading");
loading.hide();
});
</script>
--------------------------------------------------------
Create a
new page
, name should be
Download.aspx
public partial class Download : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Employee.xls"));
Response.ContentType = "application/ms-excel";
string responseString = Session["ResponseData"] + "";
Response.Write(responseString);
Response.End();
}
}