Asp.net Dynamic Validators don't work in Chrome or Safari

泪湿孤枕 提交于 2019-12-03 08:40:24

ASP.NET AJAX doesn't play well with Safari by default. It has several JavaScript hacks in it to make it work with Safari 1.x that are no longer needed. Unfortunately, this breaks AJAX for Safari 3. But, there is a solution.

Create a Safari3AjaxHack.js, like this:

// Safari 3 AJAX "issue". It no longer needs JavaScript hacks that are still implemented
// http://forums.asp.net/p/1252014/2392110.aspx

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';
}

Then define your ScriptManager like this:

<asp:ScriptManager runat="server" ID="ScriptManager1">
    <Scripts>
        <asp:ScriptReference Path="~/Scripts/Safari3AjaxHack.js" />
    </Scripts>      
</asp:ScriptManager>

I'm not sure about Chrome. I haven't had ASP.NET AJAX problems with it so far. It's pretty silly that Microsoft didn't fix this in .NET 3.5 SP1 at least, but what can you do :(

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!