Safari和ASP.NET AJAX PageRequestManager.add_endRequest函数并不总是被触发

时间:2022-07-06 17:07:52

Here's the background info first. ASP.NET 2.0 Web Site with AJAX Extensions 1.0.

这是第一个背景信息。带有AJAX Extensions 1.0的ASP.NET 2.0网站。

I have a weird issue that only occurs in Safari and I can only assume Chrome as well since they both use WebKit. I also use jQuery in the site, but currently the reference to jQuery is only loaded on one page so I don't think this is the issue.

我有一个奇怪的问题,只发生在Safari,我也只能假设Chrome,因为他们都使用WebKit。我也在网站中使用jQuery,但是目前对jQuery的引用只加载在一个页面上,所以我认为这不是问题。

I have a friendly "Processing Request..." message that appears when you submit a page async or non-async postback) and hides after postback. In the case of the async postback, I use the PageRequestManager's add_endRequest(...) method to hide the "Processing Request..." message. This works great in FireFox, IE 6/7/8 and Opera but for some reason on Safari (Windows and Mac versions), the add_endRequest(...) does not always fire. I'm all about the cross browser so just wondering if anyone has any ideas on how to fix this.

我有一个友好的“处理请求...”消息,当您提交页面异步或非异步回发时出现,并在回发后隐藏。在异步回发的情况下,我使用PageRequestManager的add_endRequest(...)方法来隐藏“处理请求...”消息。这在FireFox,IE 6/7/8和Opera中运行良好但由于某些原因在Safari(Windows和Mac版本)上,add_endRequest(...)并不总是触发。我都是关于跨浏览器的,所以只是想知道是否有人对如何解决这个问题有任何想法。

This is a show stopper for me because not only does the "Processing Request..." message appear, but I also put a transparent div on top of the entire page to prevent multiple clicks after submitting, so the page becomes unusable unless you know how to hack the CSS to hide the transparent div.

这对我来说是一个显示限制因素,因为不仅会出现“处理请求...”消息,而且我还在整个页面的顶部放置了一个透明div,以防止在提交后出现多次点击,因此除非您知道,否则页面将无法使用如何破解CSS隐藏透明div。

Here's the code snippet from my master page's markup of what I do to handle my "Processing Request..." message:

这是我的母版页标记的代码片段,用于处理我的“处理请求...”消息:

<asp:ScriptManager ID="ScriptManager1" runat="server" />
<script type="text/javascript" src="<%= ResolveClientUrl("~/Script/aspNetAjaxFix.js") %>"></script>
<script type="text/javascript" >
(function() {
    var processingID = "<%=processing.ClientID%>"
    var prm = Sys.WebForms.PageRequestManager.getInstance();

    if (prm)
    {
        prm.add_endRequest(
        function (sender, args) {
            //alert('Fired!')
            if (top['showAsyncProcessingWindow'])
            {
                setTimeout(function(){document.getElementById(processingID).className="LockOff";document.getElementById('processMe').className='processMeLockOff';if(typeof(showIE6Selects)!="undefined"){showIE6Selects();}}, 1000);
                top['showAsyncProcessingWindow'] = false;
            }

            if(args.get_error() && args.get_error().name === 'Sys.WebForms.PageRequestManagerServerErrorException')
            {
                args.set_errorHandled(args._error.httpStatusCode == 0);
            }
        });
    }
})();
</script>

And if you're wondering what aspNetAjaxFix.js is, see this question I posted on *, Internet Explorer's Operation Aborted and Latency Issue

如果您想知道aspNetAjaxFix.js是什么,请参阅我在*上发布的这个问题,Internet Explorer的操作中止和延迟问题

I also Googled this of course with not much luck. This article seemed to be relevant ,http://forums.asp.net/t/1247957.aspx but only asks the same question, no solution.

我也用Google搜索了这个没有太多运气的东西。这篇文章似乎是相关的,http://forums.asp.net/t/1247957.aspx,但只提出同样的问题,没有解决方案。

Any insight into this issue would be greatly appreciated.

任何有关这个问题的见解将不胜感激。

2 个解决方案

#1


Well after some more digging, I found out the issue. It has nothing to do with the PageRequestManager's add_endRequest(...) method and everything to do with Browser detection in the ASP.NET AJAX client-side API for Safari and WebKit based browsers.

经过一些挖掘,我发现了问题。它与PageRequestManager的add_endRequest(...)方法无关,也与基于Safari和WebKit的浏览器的ASP.NET AJAX客户端API中的浏览器检测无关。

Thanks to this post from taliesins on the ASP.NET forums, http://forums.asp.net/t/1252014.aspx. I found this post by first seeing that I was getting this error:

感谢ASP.NET论坛上的taliesins发表的这篇文章,http://forums.asp.net/t/1252014.aspx。我发现这篇文章的第一次看到我收到了这个错误:

Sys.ScriptLoadFailedException: The script 'http://localhost:2241/WebResource.axd?d=hvpXhV5kEMwLgAoaIglURevR_XTtDTBoKZ3aZWWaIvEkBXbLudri1AIv5bRs5f6licjCZMs3Z3MioQLqLTXV98582pKDHkD7BucGkKsPLz41&t=633444640020014740' failed to load. Check for:
Inaccessible path.
Script errors. (IE) Enable 'Display a notification about every script error' under advanced settings.
Missing call to Sys.Application.notifyScriptLoaded().

even though I was calling Sys.Application.notifyScriptLoaded() in my JavaScript.

即使我在我的JavaScript中调用了Sys.Application.notifyScriptLoaded()。

Show stopper resolved.

显示塞子已解决。

#2


1-create WebKit.js

Sys.Browser.WebKit = {}; //Safari 3 is considered WebKit
if (navigator.userAgent.indexOf('WebKit/') > -1) {
    Sys.Browser.agent = Sys.Browser.WebKit;
    Sys.Browser.version = parseFloat(navigator.userAgent.match(/WebKit\/(\d+(\.\d+)?)/)[1]);
    Sys.Browser.name = 'WebKit';
}

2-change ScriptManager

 <asp:ScriptManager ID="ScriptManager1" runat="server"         AsyncPostBackTimeout="600">
            <Scripts>
                <asp:ScriptReference Path="~/JScripts/webkit.js" />
            </Scripts>
        </asp:ScriptManager>

#1


Well after some more digging, I found out the issue. It has nothing to do with the PageRequestManager's add_endRequest(...) method and everything to do with Browser detection in the ASP.NET AJAX client-side API for Safari and WebKit based browsers.

经过一些挖掘,我发现了问题。它与PageRequestManager的add_endRequest(...)方法无关,也与基于Safari和WebKit的浏览器的ASP.NET AJAX客户端API中的浏览器检测无关。

Thanks to this post from taliesins on the ASP.NET forums, http://forums.asp.net/t/1252014.aspx. I found this post by first seeing that I was getting this error:

感谢ASP.NET论坛上的taliesins发表的这篇文章,http://forums.asp.net/t/1252014.aspx。我发现这篇文章的第一次看到我收到了这个错误:

Sys.ScriptLoadFailedException: The script 'http://localhost:2241/WebResource.axd?d=hvpXhV5kEMwLgAoaIglURevR_XTtDTBoKZ3aZWWaIvEkBXbLudri1AIv5bRs5f6licjCZMs3Z3MioQLqLTXV98582pKDHkD7BucGkKsPLz41&t=633444640020014740' failed to load. Check for:
Inaccessible path.
Script errors. (IE) Enable 'Display a notification about every script error' under advanced settings.
Missing call to Sys.Application.notifyScriptLoaded().

even though I was calling Sys.Application.notifyScriptLoaded() in my JavaScript.

即使我在我的JavaScript中调用了Sys.Application.notifyScriptLoaded()。

Show stopper resolved.

显示塞子已解决。

#2


1-create WebKit.js

Sys.Browser.WebKit = {}; //Safari 3 is considered WebKit
if (navigator.userAgent.indexOf('WebKit/') > -1) {
    Sys.Browser.agent = Sys.Browser.WebKit;
    Sys.Browser.version = parseFloat(navigator.userAgent.match(/WebKit\/(\d+(\.\d+)?)/)[1]);
    Sys.Browser.name = 'WebKit';
}

2-change ScriptManager

 <asp:ScriptManager ID="ScriptManager1" runat="server"         AsyncPostBackTimeout="600">
            <Scripts>
                <asp:ScriptReference Path="~/JScripts/webkit.js" />
            </Scripts>
        </asp:ScriptManager>