簡體   English   中英

進度條不會在response.end之后隱藏

[英]Progress bar not hide after response.end

我具有在項目中下載excel文件的功能。 單擊導出按鈕時,將顯示進度條。但是即使瀏覽器另存為對話框,進度條也不會消失。 問題是在未使用response.end進度欄之后。 如下所示,進度條在asp.net ajax開始請求中可見,而在結束請求.code中不可見。

可見並隱藏進度條:

Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
        function BeginRequestHandler(sender, args) {
            //             alert('B');
            var elem = args.get_postBackElement();
            ActivateAlertDiv('visible', 'AlertDiv', elem.value + ' processing...');
        }
        function EndRequestHandler(sender, args) {
            ActivateAlertDiv('hidden', 'AlertDiv', '');
        }
        function ActivateAlertDiv(visstring, elem, msg) {
            var adiv = $get(elem);
            adiv.style.visibility = visstring;
            //                    adiv.innerHTML = msg;
        }

並在導出文件下載時單擊:

Response.Clear();
                    Response.ClearHeaders();
                    Response.ClearContent();
                    Response.AddHeader("content-disposition", "attachment; filename=" + OUTPUTFILE + ".xls");
                    Response.AddHeader("Content-Type", "application/Excel");
                    Response.ContentType = "application/ms-excel.xls";
                    Response.AddHeader("Content-Length", file_New.Length.ToString());
                    Response.WriteFile(file_New.FullName);
                    Response.Flush();
                    file_New.Delete();

因為當文件發送到客戶端時響應結束。 您需要在新頁面中進行操作。

在頁面中,將代碼替換為:

Session["OUTPUTFILE"] = OUTPUTFILE;
ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "var Mleft = (screen.width/2)-(760/2);var Mtop = (screen.height/2)-(700/2);window.open( 'file.aspx', null, 'height=700,width=760,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,top=\'+Mtop+\', left=\'+Mleft+\'' );", true);

新頁面(稱為“ file.aspx”):

protected void Page_Load(object sender, EventArgs e)
{
     Response.Clear();
     Response.ClearHeaders();
     Response.ClearContent();
     Response.AddHeader("content-disposition", "attachment; filename=" + Session["OUTPUTFILE"].ToString()+ ".xls");
     Response.AddHeader("Content-Type", "application/Excel");
     Response.ContentType = "application/ms-excel.xls";
     Response.AddHeader("Content-Length", file_New.Length.ToString());
     Response.WriteFile(file_New.FullName);
     Response.Flush();
     file_New.Delete();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM