Export GridView to Excel error

Posted on 2007-08-06
Last Modified: 2012-05-05
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

            Response.AddHeader("content-disposition", "attachment; filename=Marketing Tracker Export.xls")
            Response.ContentType = "application/"

            Me.EnableViewState = False
            Response.Charset = String.Empty
            Dim myTextWriter As New System.IO.StringWriter
            Dim myHtmlTextWriter As New System.Web.UI.HtmlTextWriter(myTextWriter)

        End Sub

The code above has worked fine for me when used on a page that was not instanced from a master page. Now when i use it i get the following 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.

Details: Error Parsing near <div>
                                                   <table cells
Question by:zx10r
    LVL 3

    Expert Comment

    Are you sure this is necessarily caused by Master Pages and not ajax?  This seems like the error you get if you modify the page after the initial load using Response.Write('some html code').
    LVL 4

    Author Comment

    Yes that could very well be too. any idea on how i go about resolving this?
    LVL 3

    Accepted Solution

    Is the submit button inside the update panel used in your ajax?  If it is, try to place it outside the update panel so the postback is not being done asynchronously.
    LVL 4

    Author Comment

    That did it!!! Thanks very much for the help.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Title # Comments Views Activity
    iTextSharp 3 33
    string format question 15 39
    Cannot submit form in ASP.NET MVC 3 44
    ASP.NET MVC Create/Edit ViewModel 7 50
    In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now