Share via


MobileCapabilities Class

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

public class System.Web.Mobile.MobileCapabilities : 
   System.Web.HttpBrowserCapabilities

Remarks

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, as described in Extended Browser Capabilities.

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.

Example

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 MobileCapabilites 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>

Requirements

Namespace: System.Web.Mobile

Assembly: System.Web.Mobile

See Also

Mobile Capabilities