We have a Sharepoint solution that uses AJAX. The button that triggers this is inside an update panel.
我们有一个使用AJAX的Sharepoint解决方案。触发此按钮的按钮位于更新面板中。
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.
我们做的一件事就是生成一个MS Word文档,然后在客户端上打开它以便打印它。
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'.
消息:Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器收到的消息。此错误的常见原因是通过调用Response.Write(),响应过滤器,HttpModules或服务器跟踪来修改响应。详细信息:在“<?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.
我们可以先在Sharepoint中保存文档,然后从Sharepoint打开它,但我们不希望这样做。
8 个解决方案
#1
17
The action that causes this code to execute MUST be a postback event, and not an AJAX call.
导致此代码执行的操作必须是回发事件,而不是AJAX调用。
This is due to the nature of the way AJAX requests are processed.
这是由于处理AJAX请求的方式的性质。
#2
29
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.
如果你有updatepanel里面的按钮,这可能导致这个,如果不想移动它,只需在updatepanel上添加一个触发器,一个回发触发器。
#3
6
Keep your button outside the update panel. Then it works fine.
将您的按钮保持在更新面板之外。然后它工作正常。
#4
1
On your button click, redirect to another page that can stream any files that you might want to do this type of thing with. We use a document.aspx page in many of our sites and then pass a document id via querystring and stream the file from there.
在按钮上单击,重定向到另一个页面,该页面可以流式传输您可能想要执行此类操作的任何文件。我们在许多站点中使用document.aspx页面,然后通过查询字符串传递文档ID并从那里传输文件。
In your example, you're basically trying to change the headers for a page that's already been displayed which isn't allowed
在您的示例中,您基本上是尝试更改已经显示的页面的标题,这是不允许的
#5
1
For me the problem was duplicate control ID's in template columns of a grid view. Once I renamed the controls to be unique grid-wide, the problem disappeared!
对我来说,问题是网格视图的模板列中的重复控件ID。一旦我将控件重命名为独特的网格范围,问题就消失了!
#6
1
Try adding script manager in your page load, like this:
尝试在页面加载中添加脚本管理器,如下所示:
((ScriptManager)Master.FindControl("ScriptManager1")).RegisterPostBackControl(btnExport);
#7
1
I had an asp:Table control inside an asp:UpdatePanel control. The table had some static rows and some rows were added during a Postback event.
我在asp:UpdatePanel控件中有一个asp:Table控件。该表有一些静态行,在Postback事件期间添加了一些行。
This error occurred because rows and columns of the table did not have static IDs. So IDs changed at each postback and this cause problems with restoring ViewState for the table.
发生此错误是因为表的行和列没有静态ID。因此,每次回发都会更改ID,这会导致恢复表的ViewState出现问题。
To stop this error I disabled ViewState for the table: EnableViewState="false"
要停止此错误,我禁用了表的ViewState:EnableViewState =“false”
<asp:Table ID="PageContentTable" runat="server" ... EnableViewState="false">
#8
0
I removed the update panel around the button and it worked fine.
我删除了按钮周围的更新面板,它工作正常。
#1
17
The action that causes this code to execute MUST be a postback event, and not an AJAX call.
导致此代码执行的操作必须是回发事件,而不是AJAX调用。
This is due to the nature of the way AJAX requests are processed.
这是由于处理AJAX请求的方式的性质。
#2
29
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.
如果你有updatepanel里面的按钮,这可能导致这个,如果不想移动它,只需在updatepanel上添加一个触发器,一个回发触发器。
#3
6
Keep your button outside the update panel. Then it works fine.
将您的按钮保持在更新面板之外。然后它工作正常。
#4
1
On your button click, redirect to another page that can stream any files that you might want to do this type of thing with. We use a document.aspx page in many of our sites and then pass a document id via querystring and stream the file from there.
在按钮上单击,重定向到另一个页面,该页面可以流式传输您可能想要执行此类操作的任何文件。我们在许多站点中使用document.aspx页面,然后通过查询字符串传递文档ID并从那里传输文件。
In your example, you're basically trying to change the headers for a page that's already been displayed which isn't allowed
在您的示例中,您基本上是尝试更改已经显示的页面的标题,这是不允许的
#5
1
For me the problem was duplicate control ID's in template columns of a grid view. Once I renamed the controls to be unique grid-wide, the problem disappeared!
对我来说,问题是网格视图的模板列中的重复控件ID。一旦我将控件重命名为独特的网格范围,问题就消失了!
#6
1
Try adding script manager in your page load, like this:
尝试在页面加载中添加脚本管理器,如下所示:
((ScriptManager)Master.FindControl("ScriptManager1")).RegisterPostBackControl(btnExport);
#7
1
I had an asp:Table control inside an asp:UpdatePanel control. The table had some static rows and some rows were added during a Postback event.
我在asp:UpdatePanel控件中有一个asp:Table控件。该表有一些静态行,在Postback事件期间添加了一些行。
This error occurred because rows and columns of the table did not have static IDs. So IDs changed at each postback and this cause problems with restoring ViewState for the table.
发生此错误是因为表的行和列没有静态ID。因此,每次回发都会更改ID,这会导致恢复表的ViewState出现问题。
To stop this error I disabled ViewState for the table: EnableViewState="false"
要停止此错误,我禁用了表的ViewState:EnableViewState =“false”
<asp:Table ID="PageContentTable" runat="server" ... EnableViewState="false">
#8
0
I removed the update panel around the button and it worked fine.
我删除了按钮周围的更新面板,它工作正常。