2010-08-18 54 views
1

我有幾個鏈接按鈕,每個鏈接按鈕都打開保存對話框以讓用戶將文件保存到本地計算機。但任何鏈接被點擊後,頁面死後(沒有任何工作)和頁面必須刷新。單擊下載鏈接後頁面死機

那麼,我必須在下載完成後強制刷新,還是必須使用回發進行操作?

{ 

     StringCollection strValuesToSearch = new StringCollection(); 

     strValuesToSearch.Add("findword"); 

     string stringToReplace; 

     stringToReplace = TextBox1.Text; 




     using (StreamReader reader = new StreamReader(Server.MapPath("~/test.txt"))) 
     { 
      string result = reader.ReadToEnd(); 





      foreach (string s in strValuesToSearch) 
      { 

       if (result.Contains(s)) 

        result = result.Replace(s, stringToReplace); 




       Response.Clear(); 
       Response.AppendHeader("content-disposition", "attachment; filename=super.txt"); 
       Response.ContentType = "text/plain"; 
       UTF8Encoding encoding = new UTF8Encoding(); 
       Response.BinaryWrite(encoding.GetBytes(result)); 
       Response.Flush(); 
       Response.End(); 
+0

這取決於這些LinkBut​​ton實際上是如何工作的 - 他們如何將文件推下來? – 2010-08-18 22:47:03

+0

包含處理此問題的部分代碼。 – 2010-08-18 22:48:24

+0

發佈一些獲取要下載的文件的代碼,而不僅僅是刷新代碼。 – Parker 2010-08-18 22:52:42

回答

1

在沒有客戶端代碼,這僅僅是在胡亂猜測是什麼原因造成的問題:

  1. 用戶點擊一個鏈接按鈕
  2. JS啓動getpost阿賈克斯調用服務器,發送一些數據
  3. 服務器發送content-disposition頭文件後跟文件數據
  4. ajax進程期望其他頭文件可以說該操作已完成,並且此頭文件不會到達,因此它會無休止地鎖定UI。
相關問題