[問題] 有關asp.net 的下載功能

看板Web_Design作者 (雙手的溫柔)時間16年前 (2009/08/19 10:51), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
最近在作一個將運算結果轉為文字檔的下載功能,因此使用到Response.AddHeader, 其作法是在一個頁面上,建立一個button,讓user按下後開始運算,並將結果提供下載, 大概寫法如下, protected void OnbtnClicked(object sender, EventArgs e) { Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=" + fileName); Response.ContentType = "text/plain"; using (StreamWriter sw = new StreamWriter(response.OutputStream, System.Text.Encoding.GetEncoding("Big5"))) { //運算過程 //sw.WriteLine("..."); } label1.text = "成功"; Response.End(); } 而在運算處理完,並顯示下載對話框後,需要在頁面上顯示出一些訊息, 可是卻因Response.Clear及Reponse.End的關系,將無法正常顯示訊息, 請問各位是怎麼作的 ? 還是需要先轉址到另一個網頁,再提供單純的下載連結 ? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.125.92
文章代碼(AID): #1AYsY-hC (Web_Design)