Download file from Database generating PageRequestManagerParserErrorException
I am trying to download a file from my database to my webform. The file downloads fine, but when I click a link on the page to go to another page, I'm getting this error:
Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
I've tried two different methods of displaying the file.
1) Using a .ashx IHttpHandler with:
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest Dim id As Integer = CInt(context.Request.QueryString("ID")) context.Response.Clear() context.Response.ClearContent() context.Response.ClearHeaders()<snip code to retrieve from dbf> context.Response.ContentType = contentType context.Response.AddHeader("Content-Disposition", "attachment; filename=" + UploadedFileName) context.Response.BinaryWrite(data) context.Response.Flush() context.Response.[End]()
And 2)
With a webform page and this in code behind (snipped):
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load ' Get the file id from the query string Dim id As Integer = Convert.ToInt16(Request.QueryString("ID"))<snip code to retrieve from dbf> ' Send the file to the browser Response.AddHeader("Content-type", contentType) Response.AddHeader("Content-Disposition", "attachment; filename=" + UploadedFileName) Response.BinaryWrite(data) Response.Flush() Response.[End]()