[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 565
  • Last Modified:

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]()

Open in new window


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]()

Open in new window


Again, it is downloading the file perfectly. It's just when I attempt to click my grid to load another record, it errors as above.

Any ideas?

thanks!
0
Starr Duskk
Asked:
Starr Duskk
1 Solution
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
I was using a LinkButton in my grid and the postback generated the error.

I changed it to a simply label a href / hyperlink and it works fine now.

thanks!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now