Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
424 views
in Technique[技术] by (71.8m points)

drop down menu - Asp.Net, DropDownList, AutoPostBack and Google Chrome

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...