当提交更改时,如何避免“您确定要离开此页面吗?” 在分页中点击IE中的gridview

我的网页包含带有许多输入字段的网格视图。我想在移动到下一个标签之前向用户发出警报。 我的脚本在Mozilla Firefox和Chrome中运行良好,但在IE中,网格视图分页点击也会出现警告。我不想在分页点击上显示。但在Mozilla和chrome中这不会发生。 如何避免这种情况。

我在这里给我的剧本

 var warnMessage = "You have unsaved changes on this page!"; $(document).ready(function () { $('input:not(:button,:submit),textarea,select').change(function () { window.onbeforeunload = function () { if (warnMessage != null) return warnMessage; } }); $('input:submit').click(function (e) { warnMessage = null; }); });  

如何在gridview分页中避免此消息只在IE中单击? 有人可以帮帮我吗?

谢谢

只需在分页点击时将值设置为null

  window.onbeforeunload = null; 

更新1

试试这个而不是你的代码:

  var myEvent = window.attachEvent || window.addEventListener; var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload'; /// make IE7, IE8 compitable myEvent(chkevent, function (e) { // For >=IE7, Chrome, Firefox var confirmationMessage = 'Are you sure to leave the page?'; // a space (e || window.event).returnValue = confirmationMessage; return confirmationMessage; }); 

更新2

使用window.onbeforeunload = null后; 在您的分页控件中重新绑定更新面板中的警报尝试此解决方案,它可以帮助您解决该问题:

  $(document).ready(function () { bindPageAlert(); }); function bindPageAlert() { var myEvent = window.attachEvent || window.addEventListener; var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload'; myEvent(chkevent, function (e) { // For >=IE7, Chrome, Firefox var confirmationMessage = 'Are you sure to leave the page?'; // a space (e || window.event).returnValue = confirmationMessage; return confirmationMessage; }); } Sys.WebForms.PageRequestManager.getInstance().add_endRequest(bindPageAlert);