📜 ⬆️ ⬇️

Correct postback work in ASP.NET web applications in full screen mode on iOS devices


It all started with the fact that one of my web application stopped working correctly after I fixed it on the main screen of my iPad. More precisely, when you first start everything was fine. But then - many functions simply did not work. At first I thought that the reason was some kind of error in the code of the web application. But after a detailed study of the code and debriefing, it turned out that the whole thing is in the browser.
Rather in its full screen mode. Your web application will look great on an iPad until you decide to keep it on the main screen.

What was the problem and how to solve it - you will learn further.


Habarauser MarcusAurelius in his article " Differences in the adaptation of the site and AJAX web applications for iOS " already wrote about the main nuances and surprises when working with Safari. However, there are more surprises that may await a web developer when working with this browser. As it turned out, Safari in iOS does not always correctly support the ASP.NET postback model of events.
')
If you decide to add your web application to the iOS main screen, then at first glance everything will look great…. until for some reason the application is restarted. After this, the postback event script will not be fully functional in this browser.
The only solution to the problem may be to remove the application from the main screen, and after adding it there for a new one. Of course it is bad, and such a work scenario is no good.
After a little wandering around the Internet, I discovered that this is a fairly well-known problem and found a wonderful solution on this site .

Cause

The problem is that the iPad, iPhone and iPod Touch use different UserAgent lines, normally, and when the website starts from the main screen:


Decision


Because of its nonstandard UserAgent string, Safari for iOS is defined as an old browser that supports client-side scripts. To solve this problem, you must manually specify that this browser belongs to a new generation.
To do this, set the page property ClientTarget . By default, this property can have two values:


It is best to add the following code to the base page by overriding the OnPreInit method:

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


Thus, all AppleWebKit-based browsers will be defined as those that support client scripts.

And a little more about UserAgent


If your project is old enough, and began to be developed in the days of the .NET Framework 1.1, then after upgrading to version 4 you may encounter the following error:
The ScriptManager.SupportsPartialRendering property is set to false. Ensure that the property is set to true during an async postback.


This is due to the fact that in the web.config file the expected size of the UserAgent can be explicitly specified - up to 64 characters:
  <browserCaps userAgentCacheKeyLength="64" /> 

To solve the problem, you need to increase this value, for example, to 256 characters.
More in detail this problem is considered here .



After doing the manipulations, the web application will work fine in both normal and full-screen Safari.

Literature and sources


Source: https://habr.com/ru/post/148239/


All Articles