response 後重新整理頁面

來源:互聯網
上載者:User

標籤:style   blog   http   color   檔案   os   

response 後重新整理頁面

先要求點按鈕組建檔案,同時按鈕變灰,檔案產生好直接開啟該檔案,按鈕可用。

一,給按鈕增加點擊後變灰,頁面重新整理變可用屬性。

開啟檔案代碼如下:

 //寫出檔案        System.Text.Encoding encoding = System.Text.Encoding.GetEncoding("gb2312");        HttpResponse response = HttpContext.Current.Response;        response.HeaderEncoding = encoding;        response.Charset = encoding.HeaderName;        response.Clear();        response.ContentEncoding = encoding;        response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(pdfFile.Name));        response.AddHeader("Content-Length", pdfFile.Length.ToString());        response.ContentType = "application/pdf";        response.WriteFile(pdfFile.FullName);        HttpContext.Current.ApplicationInstance.CompleteRequest();
開啟檔案

要彈出檔案,頁面請求會立刻結束。所以這時你把按鈕的任何控制都不會執行。

二,aspx頁面:增加一個iframe

 

 <iframe id="ifrm_popMessage" src="" frameborder="0" scrolling="no" align="middle"        style="position: absolute; z-index: 100; display: none; border: 1px #62A3D2 solid;">    </iframe>

三,aspx頁面:增加JS指令碼:

////開啟檔案        function OpenPdfFile() {            document.getElementById(‘ifrm_popMessage‘).src = "OpenPdfFile.aspx?Rnd" + Math.random();        }

 四,組建檔案結束後增加如下代碼:

   

 ScriptManager.RegisterStartupScript(this.Page, ClientScript.GetType(), "myscript", "<script>OpenPdfFile();</script>", false);       

五,OpenPdfFile 頁面代碼:

/// <summary>/// 用來產生PDF檔案/// </summary>public partial class Admin_IEData_OpenPdfFile : System.Web.UI.Page{    /// <summary>    /// 頁面載入    /// </summary>       protected void Page_Load(object sender, EventArgs e)    {                 DirectoryInfo di = new DirectoryInfo(Server.MapPath("~/File/"));            string strFileName = string.Format("{0}({1}){2}.pdf", di.FullName, SessionOperate.getLoginName(), "ddpdf");                        FileInfo pdfFile = new System.IO.FileInfo(strFileName);            WriteOutFile(pdfFile);            }    #region 寫出檔案    /// <summary>    /// 寫出檔案    /// </summary>    /// <param name="pdfFile">檔案對象</param>    /// <returns>返回是否成功</returns>    protected bool WriteOutFile(FileInfo pdfFile)    {        //寫出檔案        System.Text.Encoding encoding = System.Text.Encoding.GetEncoding("gb2312");        HttpResponse response = HttpContext.Current.Response;        response.HeaderEncoding = encoding;        response.Charset = encoding.HeaderName;        response.Clear();        response.ContentEncoding = encoding;        response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(pdfFile.Name));        response.AddHeader("Content-Length", pdfFile.Length.ToString());        response.ContentType = "application/pdf";        response.WriteFile(pdfFile.FullName);        HttpContext.Current.ApplicationInstance.CompleteRequest();        return true;    }    #endregion}
Iframe頁面代碼

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.