You must Sign In to post a response.
  • Category: ASP.NET

    How to disable the progress bar after downloading the data into excel using C#

    i want to hide progress bar after downloading the data into excel.

    In run mode as follows

    i have gridview data from database. i have one Button Export to excel when i click that button gridview data is downloading to excel.

    for downloading gridview data to excel code as follows

    protected void btnExport_Click(object sender, EventArgs e)


    string script = "$(document).ready(function () { $('[id*=btnExport]').click(); });";
    ClientScript.RegisterStartupScript(this.GetType(), "load", script, true);

    Response.Buffer = true;
    Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Employee.xls"));

    Response.ContentType = "application/ms-excel";
    System.IO.StringWriter sw = new System.IO.StringWriter();
    HtmlTextWriter htw = new HtmlTextWriter(sw);

    gvEmpdetails.AllowPaging = false;

    //Applying stlye to gridview header cells
    for (int i = 0; i < gvEmpdetails.HeaderRow.Cells.Count; i++)
    gvEmpdetails.HeaderRow.Cells[i].Style.Add("background-color", "#df5015");


    Source code as follows

    <pre lang="HTML"><html xmlns="">
    <head runat="server">

    <style type="text/css">
    position: fixed;
    top: 0;
    left: 0;
    background-color: black;
    z-index: 99;
    opacity: 0.8;
    filter: alpha(opacity=80);
    -moz-opacity: 0.8;
    min-height: 100%;
    width: 100%;
    font-family: Arial;
    font-size: 10pt;
    border: 5px solid #67CFF5;
    width: 200px;
    height: 100px;
    display: none;
    position: fixed;
    background-color: White;
    z-index: 999;

    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
    function ShowProgress() {
    setTimeout(function () {
    var modal = $('<div />');
    var loading = $(".loading");;
    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 () {

    <form id="form1" runat="server">
    <div align ="Center">

    <asp:Label ID="label" Text = "Proof of conecpt" Font-Bold ="True" forecolor ="Blue" runat ="server"></asp:Label>
    <asp:GridView ID="gvEmpdetails" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
    <AlternatingRowStyle BackColor="White" />
    <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
    <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
    <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
    <SortedAscendingCellStyle BackColor="#FDF5AC" />
    <SortedAscendingHeaderStyle BackColor="#4D0000" />
    <SortedDescendingCellStyle BackColor="#FCF6C0" />
    <SortedDescendingHeaderStyle BackColor="#820000" />

    <div class="loading" align="center">
    Loading. Please wait.<br />
    <br />
    <img src="loader.gif" alt="" />

    <asp:Button ID="btnExport" runat="server" Text="Export to Excel" OnClick="btnExport_Click" />

    When i click the Exporttoexcel progress bar displaying after that data is displaying into excel.

    Then i close the excel. and in the background progress bar is running.

    i want to hide that progress bar.

    for that how can do.
  • #765783

    As I seen your code you want to hide the Div tag, you can do it in several ways like in client side and server side, i will share you how to hide it in client side.

    <div class="loading" align="center">
    Loading. Please wait.<br />
    <br />
    <img src="loader.gif" alt="" />

    this is your loading part design, in your div you are using class, if you want to hide based on class then use below code

    $( ".loading" ).hide();

    but the problem with hiding using class name is whenever you use the same class name all the div tags are hided, so to over come the above problem you have to declare the id of the div with name "divloading" and hide the div using that id.

    $( "#divloading" ).hide();

    Use the above code wherever you want...
    Hope this will helpful to you...

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #765808
    If you are using 'Response' object to download excel then user should have a download prompt and on click on save button download prompt has progress bar itself, why you want to use other progress bar ?
    progress bar is acceptable for uploading but for downloading I don't think it is useful.
    still if you want to show then here are some good links to help you

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

Sign In to post your comments