2012-12-11 32 views
1

發送文件時,我得到這個錯誤,當我嘗試從我的asp.net頁面發送一個文件:像錯誤獲取腳本asp.net

微軟JScript運行時錯誤:Sys.WebForms.PageRequestManagerParserErrorException:消息從服務器收到的無法解析。

我的代碼:

//此獲得由linkButton網格上

protected void Download(object sender, EventArgs e) 
    { 
     LinkButton lb = sender as LinkButton; 

     // save file to temp 
     Byte[] fileBytes = null; 
     using (var db = new DbContext()) 
     { 
      var id = Convert.ToInt32(lb.CommandArgument); 
      fileBytes = db.Requests.Single(x => x.Id == id).File; 
     } 
     var filePath = Path.GetTempFileName(); 
     File.WriteAllBytes(filePath, fileBytes); 

     // send 
     FileInfo fi = new FileInfo(filePath); 
     SendFile(fi); 
    } 

    private void SendFile(FileInfo file) 
    { 
     Response.ContentType = "application/zip"; 
     Response.WriteFile(file.FullName); 
     Response.End(); 


// I also tried the code below I get the same error. 

     //Response.Clear(); 
     //Response.ClearHeaders(); 
     //Response.ClearContent(); 
     //Response.AddHeader("Content-Disposition", "attachment; filename=PriceFile.zip"); 
     //Response.AddHeader("Content-Length", file.Length.ToString()); 
     //Response.ContentType = "application/zip"; 
     //Response.Flush(); 
     //Response.TransmitFile(file.FullName); 
     //Response.End(); 
    } 

回答

2

我認爲你是在發送更新面板點擊事件觸發。 嘗試在下載按鈕點擊事件全頁面回發,如果你正在使用AJAX

+0

謝謝,我想你必須有相同的問題才能知道我在更新面板中使用它。 – sprocket12

+0

也有在asp.net論壇上回答這些問題。 –

0

你要清楚你的頁面的所有HTML內容,只留下第一行(頁)

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="download.aspx.vb" Inherits="download" %>