2010-01-15 72 views
1

我有一個更新面板裏面的gridview,它將上傳的文件列表保存到應用程序中。我想,當選擇一列,SelectedIndexChanged事件返回待下載文件ajax-updatepanel文件下載問題

這裏是代碼

路徑字符串= MyFiles.Rows [filesGrid.SelectedIndex] [「文件路徑」]。的ToString( );

 FileStream fl = null; 
     try 
     { 
      fl = new FileStream(path, FileMode.Open); 

      Response.AddHeader("Content-disposition", "attachment; filename=" + fl.Name); 
      byte[] buff = new byte[fl.Length]; 
      fl.Read(buff, 0, buff.Length); 
      Response.BinaryWrite(buff); 
     } 
     catch (Exception ex) 
     { 
      lblError.Text = "Unable to download the file"; 
      lblError.ForeColor = System.Drawing.Color.Red; 
     } 
     finally 
     { 
      if (fl != null) 
       fl.Close(); 
     } 

當我點擊選擇,我收到一個JavaScript錯誤 「錯誤解析接近 '%PDF-1.4%?? 2294 0'」,並沒有什麼返回。

有沒有人遇到這個問題,或者有人知道任何可能的解決方案嗎?

在此先感謝

回答

1

我知道,它已經過了一年,但這可能有助於其他人:

我解決了我的問題(我認爲它可能與您的問題相同),添加兩個不同的按鈕,一個在更新面板內,一個在外面,但隱藏。用戶按下更新面板裏面的一個,如果一切順利,那麼還執行以下代碼

ScriptManager.RegisterStartupScript(this, typeof(SpecimenTestExport), "fireExport", ClientScript.GetPostBackEventReference(this.btnSecondButton, ""), true); 

從而導致第二個按鈕,只要異步回發完成射擊。

希望這可以幫助別人!