Asp.Net,DropDownList,AutoPostBack和Google Chrome [英] Asp.Net, DropDownList, AutoPostBack and Google Chrome

查看:217
本文介绍了Asp.Net,DropDownList,AutoPostBack和Google Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的asp.net页面(框架3.5)和一个UpdatePanel与一系列的下拉列表我想要异步填充。所有主流浏览器(Opera,Safari,IE6,IE7,FF3)都可以正常工作,但不在Chrome中。



Chrome似乎忽略了SelectedIndexChanged事件, asynch请求。



任何人都知道一个简单的解决方法吗?
谢谢!



编辑:更多信息



正如我对Adam Lassek所说,updatepanel刷新点击之后的asp:Button,但它不适用于下拉列表的 SelectedIndexChanged 事件。



updatepanel设置如下:

 < asp:UpdatePanel ID =updPanelrunat =serverUpdateMode =总是ChildrenAsTriggers =true> 

没有指定触发器,dropdows具有集 AutoPostBack =true



更新:(和重新标记)



几次尝试我发现它不是UpdatePanel的问题,但似乎下拉列表的AutoPostback无法正常工作,即使在没有ScriptManager和UpdatePanel的页面中...
我确信它只是这个项目是一个问题,因为如果我从头开始一个新的网站,并复制这个结构,在Chrome中工作正常...
我试图逐步删除所有其他的东西原来的项目找到究竟是什么问题。



如果有人在某段时间有一些想法....

解决方案

Ajax.NET Chrome & Safari 3



小而快速的测试可能是欺骗性的,因为它似乎与现有的Ajax.NET库一样正常。这是因为它设法执行第一个 Ajax请求,并且在结束时失败,因此只有当您尝试执行第二个 Ajax操作时,您会注意到它已失败。如果您在页面上放置了 UpdateProgress 控件,您会注意到,在第一个请求后,您的 UpdateProgress 控件将不会消失。



幸运的是,有一个答案!



最近有一个很好的贴子详细说明了你可以在这里找到什么:



http: //blog.turlov.com/2009/01/aspnet-ajax-compatibility-patch-for.html



它的一般要点是,两者Chrome和Safari 3在其用户代理字符串中报告为 WebKit



您需要添加一些javascript来帮助Ajax。 .NET框架识别基于WebKit的浏览器,如下所示:

  if(typeof(Sys.Browser.WebKit)== undefined){
Sys.Browser.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;
}

您需要将其添加到javascript文件中,并在您的 ScriptManager

 < asp:ScriptManager ID =ScriptManager1runat =server> 
<脚本>
< asp:ScriptReference Path =〜/ assets / javascript / WebKit.js/>
< / Scripts>
< / asp:ScriptManager>

请注意,您可以在程序集和引用中保留 WebKit.js 通过使用与此相似的ScriptReference标签:

 < asp:ScriptReference Assembly =ScriptsName =Scripts.webkit .js/>一旦你完成了所有这些,如果可能的话,尽可能的停止使用WebForms和Ajax.NET,并使用MVC和jQuery:)


I've a simple asp.net page (framework 3.5) and an UpdatePanel with a series of dropdownlist I want to populate asyncronously. All works fine in all major browsers (Opera, Safari, IE6, IE7, FF3), but not in Chrome.

Chrome seems to ignore the SelectedIndexChanged event who had to make the asynch request.

Anyone knows a simple workaround to this? Thanks!

EDIT: More Informations

As I say to Adam Lassek, the updatepanel refresh after the click to an asp:Button inside of it, but it doesn't work with the dropdown's SelectedIndexChanged event.

The updatepanel is set like:

<asp:UpdatePanel ID="updPanel" runat="server" UpdateMode="Always" ChildrenAsTriggers="true">

without Triggers specified, and the dropdows have sets AutoPostBack="true"

UPDATE: (and retagging)

After a few attempts I discover that it isn't a problem of the UpdatePanel, but it seems that the AutoPostback of dropdowns doesn't work properly, even in pages without ScriptManager and UpdatePanel... I'm sure that it is a problem concerning only this project, because if I start a new WebSite from scratch and replicate the structure of this, works fine in Chrome... I'm trying to remove step by step all the other things in the original project to find exactly what's the problem.

If anyone has some ideas in meantime....

解决方案

There is a known incompatibility with Ajax.NET and Chrome & Safari 3.

Small, quick tests can be deceptive because it will appear to work fine with the existing Ajax.NET library as is. This is because it manages to perform the first Ajax request and fails when that ends, so only when you try to perform the second Ajax action will you notice it has failed. If you put an UpdateProgress control on your page, you'll notice that after the first request your UpdateProgress control won't disapppear.

Luckily, there is an answer!

Recently there was a great post put up detailing what to do which you can find here:

http://blog.turlov.com/2009/01/aspnet-ajax-compatibility-patch-for.html

The general gist of it is that both Chrome and Safari 3 report themselves as WebKit in their userAgent strings.

You need to add a little bit of javascript in to aid the Ajax.NET framework in recognising WebKit based browsers that looks like the following:

if (typeof(Sys.Browser.WebKit) == "undefined") {
    Sys.Browser.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";
}

You need to add that to a javascript file and reference it in your ScriptManager:

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

Note that you can keep the WebKit.js in an assembly and reference that by using a ScriptReference tag similar to this:

<asp:ScriptReference Assembly="Scripts" Name="Scripts.webkit.js" />

Once you've done all that, if at all possible stop using WebForms and Ajax.NET and use MVC and jQuery :)

这篇关于Asp.Net,DropDownList,AutoPostBack和Google Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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