如何修复错误:无法解析从服务器收到的消息

Shi*_*iji 16 c# ajax sharepoint

我们有一个使用AJAX的Sharepoint解决方案.触发此操作的按钮位于更新面板中.

我们做的一件事就是生成一个MS Word文档,然后在客户端上打开它,以便打印它.

将文档发送到客户端的代码如下所示:

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

我们得到的错误是:

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'.

我们可以先在Sharepoint中保存文档,然后从Sharepoint打开它,但我们不希望这样做.

小智 34

如果你有updatepanel里面的按钮,这可能导致这个,如果不想移动它,只需在updatepanel上添加一个触发器,一个回发触发器.


Mit*_*ers 23

导致此代码执行的操作必须是回发事件,而不是AJAX调用.

这是由于处理AJAX请求的方式的性质.


Mad*_*dhu 6

将您的按钮保持在更新面板之外.然后它工作正常.


Mas*_*var 6

设置按钮以引起完整回发,如下所示:

 <Triggers>
<asp:PostBackTrigger ControlID="PrintButton" />
</Triggers>
Run Code Online (Sandbox Code Playgroud)