Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome on iPad not working with ASP.NET 4

I just downloaded Google Chrome for iPad and I noticed that it doesn't work with ASP.NET 4 websites!

For example, create a simple page:

<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

Protected Sub LinkButton1_Click(sender As Object, e As System.EventArgs)
    Response.Write("Link button was clicked")
End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton>
    </div>
    </form>
</body>
</html>

Now try clicking the Link Button, but it doesn't fire the postback event.

I can't seem to debug because there is no javascript console to find out what is going on.

!! UPDATE !!

I found that you need to select Request desktop site from the settings drop down menu in Chrome to get it to work.

!! UPDATE !!

ASP.NET does not recognize the most current versions of some browsers, and will consequently treat them as down-level browsers. (Basically: no JavaScript.) The fix is to get updated browser-definition files.

Where can we get an updated browser-definition file for Chrome?

like image 210
George Filippakos Avatar asked Jul 21 '12 11:07

George Filippakos


3 Answers

I experienced the same problem. Most everything works fine on my page, just a few items that are modified on the client side display incorrectly.

I inspected the header files that are returned from each browser on the ipad, and found that when in Chrome in Desktop mode, it was just pretending to be an a Mac Box, sending the following in the header: Mozilla/5.0+(Macintosh;+Intel+Mac+OS+X+10_7_3)+AppleWebKit/534.53.11+(KHTML,+like+Gecko)+Version/5.1.3+Safari/534.53.10

and when it is in standard mode it sens the following in the header: Mozilla/5.0+(iPad;+CPU+OS+6_0+like+Mac+OS+X)+AppleWebKit/534.46.0+(KHTML,+like+Gecko)+CriOS/21.0.1180.82+Mobile/10A403+Safari/7534.48.3

I attempted to add a new browser to my "app_browsers" directory, copying "chrome" and re-naming it "chromeios", and replacing the "chrome" useragent inside with CriOS. This did nothing, and I am not even sure that the files in the "app_Browsers" directory are doing anything.

That's when I came across this question. The answers suggested by the users vamshik and Jay Douglass, when put together worked for me.

Jay's however was incorrect in that it has the wrong user agent (it should be "crios").

User geo1701 however complained about adding this to every page. This can easily be done by creating a class that inherits System.Web.UI.Page and then add above code with the "protected void Page_PreInit" event, and then replace the inheritance on each web page with your new class. Then if you ever need to add something that is needed in every page, you have that class to add it too.

I am also wondering if there is a way to add it to the global.asax class? but I am guessing not...

Still looking for a better solution. If I find one, I will update.

Found the following related posts:

Chrome for iOS user agent on iPad

ASP.NET Webforms Doesn't Render Postback JavaScript Function for Chrome/iOS

UPDATE I found this by Scott Hanselman. While he is talking about cookies, I think his suggestions may send us in the right direction.

OK! FINAL UPDATE!!!

After installing .NET Framework 4.5, and removing the files from my app_browsers directory, the Chrome on my iPad is working. I looked at the entries in the new .Browser files provided by .net 4.5, and there was nothing remarkable, so I am guessing that there was more too it then some updating to the the .browser files.

The .Net framework 4.5 can be downloaded here

like image 109
Rootberg Avatar answered Oct 02 '22 16:10

Rootberg


ASP.NET may be incorrectly detecting Chrome on iPad as a "downlevel" browser that doesn't support JavaScript. ASP.NET uses the user agent string to detect down level browsers. To force Chrome to be detected as an "uplevel" browser, you can do this:

protected void Page_PreInit(object sender, EventArgs e)
{
    if (Request.UserAgent != null && Request.UserAgent.IndexOf("chrome", StringComparison.OrdinalIgnoreCase) > -1)
    {
        this.ClientTarget = "uplevel";
    }
}
like image 33
Jay Douglass Avatar answered Oct 02 '22 15:10

Jay Douglass


Below worked for me...

if (Request.UserAgent != null && Request.UserAgent.IndexOf("crios", StringComparison.OrdinalIgnoreCase) > -1)
{
    this.ClientTarget = "uplevel";
}
like image 30
vamshik Avatar answered Oct 02 '22 15:10

vamshik