Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix error: The message received from the server could not be parsed

We have a Sharepoint solution that uses AJAX. The button that triggers this is inside an update panel.

One of the things that we do is generate a MS Word document, that is then opened on the client so that it can be printed.

The code that sends the document to the client looks like this:

    void OpenFileInWord(byte[] data)
    {
        Response.Clear();
        Response.AddHeader("Content-Type", "application/msword");
        Response.BinaryWrite(data);
        Response.Flush();
        Response.End();
    }

The error that we are getting is:

Message: 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 '<?mso-application pr'.

We could save the document in Sharepoint first, and then open it from Sharepoint, but we would prefer not to do this.

like image 721
Shiraz Bhaiji Avatar asked Oct 12 '09 13:10

Shiraz Bhaiji


4 Answers

If you have the button inside updatepanel this maybe causing this, if don´t want to move it, just add a trigger for the button on the updatepanel, a postback trigger.

like image 96
MauricioMCP Avatar answered Nov 10 '22 00:11

MauricioMCP


The action that causes this code to execute MUST be a postback event, and not an AJAX call.

This is due to the nature of the way AJAX requests are processed.

like image 24
Mitchel Sellers Avatar answered Nov 09 '22 23:11

Mitchel Sellers


Keep your button outside the update panel. Then it works fine.

like image 7
Madhu Avatar answered Nov 09 '22 23:11

Madhu


Set your button to cause full postback like this:

 <Triggers>
<asp:PostBackTrigger ControlID="PrintButton" />
</Triggers>
like image 5
Masoumeh Karvar Avatar answered Nov 09 '22 23:11

Masoumeh Karvar