【发布时间】:2012-09-10 21:50:58
【问题描述】:
我正在开发一个 asp.net(框架 4),它要求用户在尝试离开页面而不保存更改时收到通知。好吧,我通过 JavaScript 调用 onbeforeunload 函数找到了解决方案。在 IE 中效果很好,但在 Firefox、Safari 或 Chrome 中效果不佳。
现在问题出在此处。我正在使用 AJAX 回发,如果在离开页面之前提示用户保存更改,则更新面板内的任何控件都不会再回发到服务器。例如,如果按下更新面板内的保存按钮,则不会发生任何事情。
这里有一些代码sn-ps
javascript:
window.onbeforeunload = function (e) {
if (doBeforeUnload() == true) {
var ev = e || window.event;
// For IE and Firefox prior to version 4
if (ev) {
ev.returnValue = "You have modified the data entry fields since the last time it was saved. If you leave this page, " +
"any changes will be lost. To save these changes, click Cancel to return to the page, and then Save the data.";
}
// For Safari
return "You have modified the data entry fields since the last time it was saved. If you leave this page, " +
"any changes will be lost. To save these changes, click Cancel to return to the page, and then Save the data.";
}
}
ASP.NET:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<%--no controls inside of this panel will postback to server if user clicks the “Stay on Page” button--%>
</ContentTemplate>
</asp:UpdatePanel>
网上好像有很多帖子,但没有解决方案。除了不使用异步回发之外还有什么想法吗?
【问题讨论】:
标签: javascript asp.net asp.net-ajax updatepanel