问题: 当用户点击删除按钮时,程序调用Response.write("<script>alert('是否继续')</script>")是页面会弹出错误:
Sys.WebForms.PageRequestManagerParserErrorException:The message received from the server count 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 '<script language=javascript'. 原因: 由于页面中加入了UpdatePanel,而且删除按钮在UpdatePanel里面。 当用户点击删除按钮时,ajax1.0不支持Response.write里面调用javascript。
解决办法: 在UpdatePanel的属性中添加PostBackTrigger,ControlID为该删除按钮,如下:
<asp:ScriptManager ID="ScriptManager1" runat="server" /> <div> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <Triggers> <asp:PostBackTrigger ControlID="Button1" /> </Triggers> <ContentTemplate> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> </ContentTemplate> </asp:UpdatePanel> </div>
此时我们再单击 Button1 将出现页面闪烁,说明实现了整页回送。PostBackTrigger 只有一个属性:ControlID。