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?
Who is Participating?
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
Before you do the .WriteFile you could Try
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
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

HLRosenbergerAuthor Commented:
The_Big_Daddy - What article?

OriNetworks - I did try Clear.  Not help

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

            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())
HLRosenbergerAuthor Commented:

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.EnablePartialRendering = False

        End Sub
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

Now, why does this work?  What does RegisterPostBackControl do that cause the error message to go away?
HLRosenbergerAuthor Commented:
johny_bravo1 - Why does adding a postbacktrigger for the button fix this problem?
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:

HLRosenbergerAuthor Commented:
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

From novice to tech pro — start learning today.