I am hooking the window.onbeforeunload event in an aspx page. I need that not to fire if I page a GridView that's in an UpdatePanel on the same page.
我在aspx页面中挂钩window.onbeforeunload事件。如果我在同一页面上的UpdatePanel中分页GridView,我需要不要触发。
I have tried hooking the PageRequestManager's initializeRequest event but this fires too late, i.e. after onbeforeunload. I have also tried checking PageRequestManager.get_isInAsyncPostBack() in my onbeforeunload handler but that returns false too, gah!
我试过挂钩PageRequestManager的initializeRequest事件,但这种情况发生得太晚了,即在onbeforeunload之后。 ,我也尝试在我的onbeforeunload处理程序中检查PageRequestManager.get_isInAsyncPostBack(),但也返回false,哇!
I have read this SO thread :
我已阅读此SO帖子:
But that doesn't make sense to me other than GridView page links cause an unload whereas buttons in a GridView column do not? Anybody know how to solve this? I'm guessing only way is to attach client-side click handler to all the GridView's page anchors to set some boolean flag, but I'm not sure how to accomplish that in a reliable manner.
但这对我来说没有意义,除了GridView页面链接导致卸载,而GridView列中的按钮没有?谁知道怎么解决这个问题?我猜测唯一的方法是将客户端点击处理程序附加到所有GridView的页面锚点以设置一些布尔标志,但我不确定如何以可靠的方式完成它。
1 个解决方案
#1
Ok JQuery to the rescue!
好的JQuery来救援!
<script type="text/javascript">
var flag = true;
window.onbeforeunload = beforeUnloading;
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(initPagers);
function initPagers() {
$(".gridViewPagerStyle").click(function() { flag = false; });
}
function beforeUnloading(){
if(flag)
return "unloading";
flag = true;
}
</script>
:
:
<asp:GridView ... PagerStyle-CssClass="gridViewPagerStyle" ... />
:
:
Set a Css class for all pager links, use that to append javascript click handlers that set a flag when clicked, use flag to avoid onbeforeunload
为所有寻呼机链接设置一个Css类,使用它来附加点击时设置标志的javascript点击处理程序,使用标志来避免onbeforeunload
#1
Ok JQuery to the rescue!
好的JQuery来救援!
<script type="text/javascript">
var flag = true;
window.onbeforeunload = beforeUnloading;
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(initPagers);
function initPagers() {
$(".gridViewPagerStyle").click(function() { flag = false; });
}
function beforeUnloading(){
if(flag)
return "unloading";
flag = true;
}
</script>
:
:
<asp:GridView ... PagerStyle-CssClass="gridViewPagerStyle" ... />
:
:
Set a Css class for all pager links, use that to append javascript click handlers that set a flag when clicked, use flag to avoid onbeforeunload
为所有寻呼机链接设置一个Css类,使用它来附加点击时设置标志的javascript点击处理程序,使用标志来避免onbeforeunload