Archive for July, 2012|Monthly archive page

Sys.WebForms is undefined on iPad

Is your site working perfectly fine everywhere except as an iPad full-screen application?  Is it giving you a “Sys.WebForms” is undefined error in javascript? Or is it acting like ajax is disabled in some other way?

This was an incredibly difficult problem to track down, so I thought I’d share it here to pass on the knowledge.

In my case, I was using Telerik’s RadScriptManager, but later I found it wasn’t limited to Telerik’s controls, but to any ajax-related code.  However, I point out Telerik in particular because on their forums they offered a dozen solutions that led me in the wrong direction.

The root problem is that the iPad full-screen app gives a user-agent header that ASP.Net does not recognize, so it believes that the browser does not support ajax.  This results in the ScriptManager not including “MicrosoftAjaxWebForms.js” and all sort of other things related to ajax panels not loading.

So the solution is to tell ASP.Net that the user-agent in question does support ajax.  Luckly we have a custom base page for all of our ASPX files, so I only had to add this in one place:

protected override void OnPreInit(EventArgs e)
{
    if (Request.UserAgent != null && Request.UserAgent.IndexOf("AppleWebKit", StringComparison.CurrentCultureIgnoreCase) > -1)
    {
        this.ClientTarget = "uplevel";
    }

    base.OnPreInit(e);
}

I found this solution here.  Thank you! http://blog.lavablast.com/post/2011/05/29/Gotcha-iPad-versus-ASPNET.aspx#comment

Advertisements