ASP.NET AJAX燮preSS onbeforeunload的从UpdatePanel的AJAX请求 [英] ASP.NET AJAX suppress onbeforeunload for AJAX requests from updatepanel

查看:123
本文介绍了ASP.NET AJAX燮preSS onbeforeunload的从UpdatePanel的AJAX请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我钩在一个aspx页面的window.onbeforeunload事件。我需要的没有的到,如果我第一个GridView这是在一个UpdatePanel在同一页上闪光。

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.

我试图钩住PageRequestManager可以的initializeRequest事件,但这种触发为时已晚,即onbeforeunload的经过。我也试过在我onbeforeunload的处理程序检查PageRequestManager.get_isInAsyncPostBack(),但也返回false,GAH!

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!

我已阅读本SO主题:

<一个href="http://stackoverflow.com/questions/537702/can-i-$p$pvent-window-onbeforeunload-from-being-called-when-doing-an-ajax-call">537702

但是,这并没有什么意义,我以外的GridView页面链接导致卸载,而在GridView栏按钮不?任何人都知道该如何解决呢?我猜唯一的办法就是连接客户端的click处理所有GridView的页面锚设置一些布尔标志,但我不知道如何实现这一目标以可靠的方式。

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.

推荐答案

确定jQuery来救援!

Ok JQuery to the rescue!

<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" ... />

:
:

所有寻呼机环节设置一个CSS类,用它来添加JavaScript的点击处理程序设置一个标志,点击后,用标志,以免onbeforeunload的

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

这篇关于ASP.NET AJAX燮preSS onbeforeunload的从UpdatePanel的AJAX请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆