Device Evaluation Methods

For ASP.NET mobile controls, device evaluation methods enable you to create named filters that you can use directly in the HasCapability method. You can also use these filters indirectly in the <Choice> element of the <DeviceSpecific> section.

To specify a named filter, add an entry to the <deviceFilters> section of the Web.config file. The following example demonstrates defining a new device filter, isHTML32.

<filter name="isHTML32" compare="PreferredRenderingType"
   argument="html32" />

At run time, this filter compares the value of the PreferredRenderingType property of the current request's MobileCapabilities instance and the value html32.

The following example illustrates two ways to define a new capability, GPSEnabled. Only the first specifies the assembly. The type for the second is assumed to be in an implicitly loaded assembly. For more information, see Specifying Fully Qualified Type Names.

The following code implements the capability.

[C#]

namespace MyNamespace
{
   public class MyCapabilityEvaluators
   {
      public static bool IsGPSEnabled(
         System.Web.Mobile.MobileCapabilities capabilities,
         String unusedArg)
      {
         processing code
      }
   }
}

Add the following to the appropriate Web.config file to add the new capability.

<deviceFilters>
   <filter name="GPSEnabled" 
      type="MyNamespace.MyCapabilityEvaluators, MyAssembly"
      method="IsGPSEnabled"/>
</deviceFilters>

During rendering, one of the choices within a <DeviceSpecific> element is selected based on the capabilities of the target device. The comparison first checks the filter name against filters defined on the page. If a method of the appropriate signature exists in Web.config or the hierarchy, this method is used to evaluate the <Choice> entry for a filter of the appropriate name.

See Also

Device Capabilities Table | Device Filtering Recommendations | Device-Specific Rendering | Evaluating Capabilities Programmatically | <filter> Element