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?
LVL 1
HLRosenbergerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontyWeb Ninja at largeCommented:
have a read through this article, including the comments, it seems there are various possibilities for this error message
0
OriNetworksCommented:
Before you do the .WriteFile you could Try
Response.Clear
0
Johny BravoCommented:
Can you share your code?

Is your button on which this code is run is in updatepanel?

If the button is in updatepanel then add postbacktrigger for this
0
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

HLRosenbergerAuthor Commented:
The_Big_Daddy - What article?

OriNetworks - I did try Clear.  Not help


johny_bravo1 - How do I add  postbacktrigger?
0
HLRosenbergerAuthor Commented:
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)
0
HLRosenbergerAuthor Commented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HLRosenbergerAuthor Commented:
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
0
HLRosenbergerAuthor Commented:
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?
0
HLRosenbergerAuthor Commented:
johny_bravo1 - Why does adding a postbacktrigger for the button fix this problem?
0
HLRosenbergerAuthor Commented:
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.
0
HLRosenbergerAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.