Link to home
Start Free TrialLog in
Avatar of HLRosenberger
HLRosenbergerFlag for United States of America

asked on

Response.WriteFile gives error message

When I do a Response.WriteFile, I'm getting this error message:

Error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.

If I do the Response.WriteFile from a blank WEB page, it works OK.  

Do I need to do some sort of cleanup in the HTTP response object?
Avatar of Big Monty
Big Monty
Flag of United States of America image

have a read through this article, including the comments, it seems there are various possibilities for this error message
Avatar of OriNetworks
OriNetworks

Before you do the .WriteFile you could Try
Response.Clear
SOLUTION
Avatar of Johny Bravo
Johny Bravo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HLRosenberger

ASKER

The_Big_Daddy - What article?

OriNetworks - I did try Clear.  Not help


johny_bravo1 - How do I add  postbacktrigger?
Here the codebehind:

            Response.Clear()
            Response.ClearHeaders()
            Response.ClearContent()
            Response.AddHeader("content-disposition", "attachment; filename=" + filename)
            Response.AddHeader("Content-Type", "application/Excel")
            Response.ContentType = "application/vnd.xls"
            Response.AddHeader("Content-Length", File.Length.ToString())
            Response.WriteFile(File.FullName)
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I also have this in page init:

  Public Sub aaa() Handles Me.Init

            Dim scriptManager As New ScriptManager
            scriptManager.GetCurrent(Me.Page)
            scriptManager.RegisterPostBackControl(Me.btnExcelExport)
            scriptManager.EnablePartialRendering = False

        End Sub
The_Big_Daddy - I got it working.  I goofed in accessing the scriptManager on the page.  See previous post.  I already had a scriptManager in a mater page.  So in page init I had to find the scriptManager control and the do this:

Dim sm As ScriptManager
sm.RegisterPostBackControl(Me.btnExcelExport)


Now, why does this work?  What does RegisterPostBackControl do that cause the error message to go away?
johny_bravo1 - Why does adding a postbacktrigger for the button fix this problem?
I've requested that this question be closed as follows:

Accepted answer: 0 points for HLRosenberger's comment #a39556744
Assisted answer: 250 points for johny_bravo1's comment #a39556216
Assisted answer: 250 points for The_Big_Daddy's comment #a39556535

for the following reason:

thanks.
Thanks