configuringaspnetajaxtorecognizeiemobile

Cancel
Save
Edit
Summary: Shows how to add the appropriate configuration information for ASP.NET AJAX to recognize and support IE Mobile.

ASP.NET AJAX and IE Mobile

Starting with IE Mobile 6.12, the version included with Windows Mobile 6.0 AKU 0.2 (the first released version of WM6), IE Mobile includes the features necessary to support ASP.NET AJAX. The versions of ASP.NET AJAX available to Visual Studio 2005 and Visual Studio 2008 Beta 2 (the version available at this writing) do not recognize this support therefore as the developer of the ASP.NET AJAX site, you must include additional information for the site to recognize the IE Mobile's support.

Note: The issues discussed here are specific to IE Mobile support of ASP.NET AJAX. Windows Mobile devices have included support for AJAX going back to Windows Mobile 2003. The level of AJAX feature support has increased with each release. Windows Mobile 6 is the first version to include all of the features necessary to support AJAX pages created by ASP.NET.

Adding the Appropriate Browser Configuration Information

The reason that ASP.NET AJAX does not recognize IE Mobile's support is that ASP.NET AJAX doesn't know how to fully interpret the User Agent header provided by IE Mobile. Adding a browser file that includes the information necessary to recognize IE Mobile solves this problem.
  1. Add a new item to your project
  2. Select "Browser File" from the template list
  3. Say "Yes" when asked whether to put the file in the App Browsers folder
  4. Add the following content to the new file.
Note: Multiple source documents along with experimentation are the source of this browser file contents. For notes, source details, and additional information on the browser file contents, see the blog entry: IE Mobile Browser Definition File v2.0

		 <!--
		    Browser capabilities information that enables Visual Studio 2005 
		    ASP.NET AJAX to recognize IE Mobile 6.12 (version on Windows Mobile 6)
		 -->
	

<browsers>
		    <browser id="IEMobile" parentID="WinCE">
		        <identification>
		            <userAgent match="IEMobile (?'version'\d+\.\d+)" />
		        </identification>
		        <capture>
		            <userAgent match="MSIE (?'msieMajorVersion'\d+)" />
		            <header name="UA-PIXELS" match="(?'screenWidth'\d+)x(?'screenHeight'\d+)" />
		        </capture>
		        <capabilities>
		            <capability name="breaksOnInlineElements"                  value="false" />
		            <capability name="browser"                                 value="IEMobile" />
		            <capability name="cdf"                                     value="true" />
		            <capability name="defaultScreenPixelsHeight"               value="${screenHeight}" />
		            <capability name="defaultScreenPixelsWidth"                value="${screenWidth}" />
		            <capability name="ecmascriptversion"                       value="1.2" />
		            <capability name="javaapplets"                             value="true" />
		            <capability name="jscriptversion"                          value="5.6" />
		            <capability name="maximumRenderedPageSize"                 value="800000" />
		            <capability name="msdomversion"                            value="3.0" />
		            <capability name="numberOfSoftkeys"                        value="2" />
		            <capability name="requiresAbsolutePostbackUrl"             value="false" />
		            <capability name="requiresCommentInStyleElement"           value="false" />
		            <capability name="requiresHiddenFieldValues"               value="false" />
		            <capability name="requiresOnEnterForwardForCheckboxLists"  value="false" />
		            <capability name="requiresXhtmlCssSuppression"             value="false" />
		            <capability name="preferredImageMime"                      value="image/jpg" />
		            <capability name="preferredRenderingMime"                  value="application/xhtml+xml" />
		            <capability name="preferredRenderingType"                  value="xhtml-basic" />
		            <capability name="screenPixelsHeight"                      value="${screenHeight}" />
		            <capability name="screenPixelsWidth"                       value="${screenWidth}" />
		            <capability name="supportsBodyClassAttribute"              value="true" />
		            <capability name="supportsCallback"                        value="true" />
		            <capability name="supportsDivNoWrap"                       value="false" />
		            <capability name="supportsNoWrapStyle"                     value="false" />
		            <capability name="supportsSelectFollowingTable"            value="true" />
		            <capability name="supportsStyleElement"                    value="true" />
		            <capability name="supportsTitleElement"                    value="false" />
		            <capability name="supportsUrlAttributeEncoding"            value="true" />
		            <capability name="supportsXmlHttp"                         value="true" />
		            <capability name="tagwriter"                               value="System.Web.UI.HtmlTextWriter" />
		            <capability name="type"                                    value="MSIE ${msieMajorVersion}" />
		            <capability name="vbscript"                                value="true" />
		            <capability name="version"                                 value="${version}" />
		            <capability name="w3cdomversion"                           value="1.0" />
		            <capability name="win32"                                   value="true" />
		            <capability name="xml"                                     value="true" />
		        </capabilities>
		    </browser>
	

		    <!--
		    **************************************************************
		    Exclude IE Mobile Version On Late Releases of Windows Mobile 5 
		    **************************************************************
		    WM5 AKU3.3 and later shipped with a version of IE Mobile that sends the new user agent string 
		    that includes the text "IEMobile", but does not provide the features necessary to work with 
		    ASP.NET AJAX so set capabilities appropriatly so that the ASP.NET server will render the page 
		    without the inclusion of AJAX features. 
		    -->
		    <browser id="IEMobileNotAspNetAjaxCapable" parentID="IEMobile">
		        <identification>
		            <capability name="version" match="6\.8" />
		        </identification>
		        <capabilities>
		            <capability name="supportsCallback"                        value="false" />
		            <capability name="w3cdomversion"                           value="0.0" />
		        </capabilities>
		    </browser>
	

		    <!--
		    ************************
		    Screen Color information
		    ************************
		    UA-COLOR Header
		    Set isColor capability to true and set the [screenBitDepth] based on the header value
		    Example UA-COLOR=color32 -> [screenBitDepth=32,] UA-COLOR=color16 -> [screenBitDepth=16,] etc.
		    -->
	

		    <gateway id="IEMobileColorScreenBitDepth" parentID="IEMobile">
		        <identification>
		            <header name="UA-COLOR" match="color(?'bitDepth'\d+)" />
		        </identification>
		        <capabilities>
		            <capability name="screenBitDepth"                          value="${bitDepth}" />
		            <capability name="isColor"                                 value="true" />
		        </capabilities>
		    </gateway> 
	

		    <!--
		    ************************
		    Pocket PC Input Type
		    ************************
		    -->
		    <gateway id="IEMobilePPC" parentID="IEMobile">
		        <identification>
		            <header name="UA-OS" match="Pocket PC" />
		        </identification>
		        <capabilities>
		            <capability name="inputType"                               value="virtualKeyboard" />
		        </capabilities>
		    </gateway> 
	

		    <!--
		    ************************
		    File Upload Capabilities
		    ************************
		    Upload is only supported on Windows Mobile 6 Professional
		    No header available that identifies a device as Professional vs. Classic so must infer 
		    through the combination of "Pocket PC" appearing in the UA-OS header and the device's ability
		    to initiate a voice call (capability is set by the UA-VOICE handling in gateway.browser).
		    This is not 100% reliable due to the fact that the voice capability may report 
		    false when the device has the phone turned off, 
		    -->
		    <gateway id="IEMobileUploadSupport" parentID="IEMobile">
		        <identification>
		            <header name="UA-OS" match="Pocket PC" />
		            <capability name="canInitiateVoiceCall" match="true"/>
		        </identification>
		        <capabilities>
		            <capability name="supportsFileUpload"   value="true" />
		        </capabilities>
		    </gateway>
	

</browsers>

Statically Instruct ASP.NET to Assume Internet Explorer 5 Support

You can instruct ASP.NET to ignore a browser's User Agent header and instead assume that the browser is a specific client by including the ClientTarget value in the <@% Page %> directive. Setting the ClientTarget to "ie5" tells ASP.NET to communicate to the client as if it is Internet Explorer 5 which works correctly with IE Mobile 6.12.
The <%@ Page %> directive would look similar to the following.
		 <%@ Page Language="C#" MasterPageFile="~/Site.master" ClientTarget="ie5" utoEventWireup="true" CodeFile="MyBaseClass.aspx.cs" Inherits="MyBaseClass" Title="Example"%>
	
Keep in mind that setting the ClientTarget value on a page affects all of the clients of that page. Setting the ClientTarget to "ie5" causes the page to treat every client as if it is Internet Explorer 5 which can limit your ability to take advantage of features that might be available in newer browsers.

Dynamically Instruct ASP.NET to Assume Internet Explorer 5 Support for IE Mobile clients

Rather than force the page to assume that all clients are Internet Explorer 5, you can conditionally set the ClientTarget value in code when the incoming request is from a Windows Mobile device.
To do this correctly, you need set the ClientTarget value after the Request.UserAgent value is set but before the server side processing occurs that relies on all the various capability values stored in the Request.Browser instance. To meet these requirements, you need to override the FrameworkInitialize method in your page's codebehind class and set the ClientTarget value there.
The following code shows how to test the UserAgent value for IE Mobile and set the ClientTarget appropriately.
		 public partial class _Default : System.Web.UI.Page 
		 {
		   protected void Page_Load(object sender, [EventArgs] e)
		   {
		     // Do Page Load Stuff
		   }
		   protected override void [FrameworkInitialize()]
		   {
		     [base.FrameworkInitialize();]
		     // When client is IE Mobile, set target behavior to IE5
		     if (Request.UserAgent.IndexOf("IEMobile") > -1)
		       [ClientTarget] = "ie5";
		   }
		 }
	
Note: The FrameworkInitialize method is exactly where the generated ASPX page class sets the ClientTarget value when you include the ClientTarget in the <%@ Page %> directive.