変更を保存せずにページを離れようとしている場合にユーザーに通知する必要があるasp.net(フレームワーク4)に取り組んでいます。onbeforeunload
JavaScriptを介して関数を呼び出すことで解決策を見つけました。IEではうまく機能しますが、Firefox、Safari、Chromeでは機能しません。
ここで問題が発生します。私はAJAXポストバックを使用しており、ページを離れる前にユーザーが変更を保存するように求められた場合、更新パネル内のコントロールはサーバーにポストバックしなくなります。たとえば、更新パネルの内側にある保存ボタンを押しても、何も起こりません。
ここにいくつかのコードスニペットがあります
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>
ネット上にはたくさんの投稿があるようですが、解決策はありません。非同期ポストバックを使用しない以外に何かアイデアはありますか?