Export (0) Print
Expand All

MobileCapabilities Class

Provides a single source for accessing capability information about a client device and for performing queries against device capabilities.

Namespace: System.Web.Mobile
Assembly: System.Web.Mobile (in system.web.mobile.dll)

public class MobileCapabilities : HttpBrowserCapabilities
public class MobileCapabilities extends HttpBrowserCapabilities
public class MobileCapabilities extends HttpBrowserCapabilities
Not applicable.

The MobileCapabilities class extends the HttpBrowserCapabilities class. The MobileCapabilities class offers a large number of read-only properties that provide type-safe access to the Browser object's capabilities dictionary.

You can use the Browser property of the HttpRequest object to point to an instance of a MobileCapabilities object, which can then be used to read the capabilities of the requesting browser and device.

During the page load, the MobileCapabilities object obtains the capabilities through the Browser property as previously discussed. The PreferredRenderingMime and the ScreenCharactersWidth properties of the MobileCapabilities object report back to the browser by setting properties on the HttpResponse object and also by programmatically setting the Text property of certain controls on the page.

<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" 
    Language="c#" %>
<script language="c#" runat="server">
public void Page_Load(Object sender, EventArgs e)
{
    System.Web.Mobile.MobileCapabilities currentCapabilities;
    MobileCapabilities currentCapabilities = 
        (MobileCapabilities)Request.Browser;
    // Programatically find the mobile capabilities without using 
    // DeviceSpecific Filters.
    if(currentCapabilities.PreferredRenderingMIME=="text/html")
    {
        Label2.Text = "You are using an html supported device.";
    }
    else if(currentCapabilities.PreferredRenderingMIME == 
        "text/vnd.wap.wml")
    {
        Label2.Text = "You are using a wml supported device.";
    }
    Label1.Text = "Screen Width (chars): " + 
        currentCapabilities.ScreenCharactersWidth;
 }
 </script>
 <Mobile:Form runat="server" id=frmTemplate >
      <mobile:label ID="Label1" runat="server" />
      <mobile:label ID="Label2" runat="server" />
 </Mobile:Form>

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1

Community Additions

ADD
Show:
© 2014 Microsoft