I get this error when I try and send a file from my asp.net page :
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.
My code :
// this gets triggered by a linkButton on a grid
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();
}
I think you are sending the click event in update panel.
Try full page postback on Download button click event if you are using ajax