1. 程式人生 > >未能分析從服務器收到的消息,.cs文件裏面用response.write輸出js彈框出錯,用了局部跟新

未能分析從服務器收到的消息,.cs文件裏面用response.write輸出js彈框出錯,用了局部跟新

scrip hive htm onclick orm pda 但是 parser 彈框

轉載:https://www.cnblogs.com/shenyixin/archive/2012/03/08/2385376.html

中文:

Sys.WebForms.PageRequestManagerParserErrorException:

無法分析從服務器收到的消息,之所以出現此錯誤,常見的原因是:通過調用Response.Write()修改相應時,將啟用響應篩選器、HttpModules或服務器追蹤。

詳細信息:分析附近的“輸出內容”時出錯。


解決方法如下:

1.如果調用Response.Write()方法的服務器控件在使用UpdatePanel的頁面,則只需要在UpdatePanel下增加一個<Triggers>節點,通過PostBackTrigger註冊一下改控件就可以了。代碼如下:

1. <asp:ScriptManager ID="ScriptManager1" runat="server">
2. </asp:ScriptManager>
3. <asp:UpdatePanel ID="UpdatePanel1" runat="server">
4. <Triggers>
5. <asp:PostBackTrigger ControlID="Button2" /> <!--Button2就是下面那個需要在Button2_Click事件裏使用Response.Write()的按鈕ID-->
6. </Triggers>
7. <ContentTemplate>
8. <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" />
9. <asp:UpdateProgress ID="UpdateProgress1" runat="server">
10. <ProgressTemplate></ProgressTemplate>
11. </asp:UpdateProgress>
12. </ContentTemplate>
13. </asp:UpdatePanel>

2.但是,如果是在母版頁中使用UpdatePanel,則不能通過以上方法來解決,否則或出現類似以下錯誤:

A control with ID ‘btnExport‘ could not be found for the trigger in UpdatePanel ‘UpdatePanel1‘.

這主要是UpdatePanel1找不到<asp:PostBackTrigger ControlID="btnExport" />中註冊的控件,因為,我們一般沒有在母版頁中添加這個控件(btnExport)。(當然,如果在UpdatePanel的<ContentTemplate> 節點下添加了ID為btnExport的控件,則不會出錯。)

如果出現這樣的錯誤該怎麽辦呢,我的解決方法是在需要用到Response.Write()方法的控件所在頁碼的Page_Load事件中添加如下代碼:
((ScriptManager)Master.FindControl("ScriptManager1")).RegisterPostBackControl(btnExport);
//ScriptManager1是<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>的ID

未能分析從服務器收到的消息,.cs文件裏面用response.write輸出js彈框出錯,用了局部跟新