Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Device Filtering Recommendations

Device Filtering Recommendations

This section describes how to create comparison-based and evaluator-delegate filters for ASP.NET mobile controls. Device filters provide a convenient mechanism for creating named criteria that developers can use to specify devices or properties of mobile devices. These filters are stored in the <deviceFilters> section of the Web.config configuration file.

Each device filter matches one or more types of devices, and a single device can match multiple filters. For example, a Pocket PC might match the filter IsColor as a color device, IsPDA as a PDA, and IsHTML32 as an HTML-based browser.

For each filter, you add a <filter> element in the <deviceFilters> section of web.config. You can specify comparison-based filters and evaluator-delegate-based filters.

Comparison-Based Filters

Comparison-based filters compare a MobileCapabilities property value against an argument. The syntax for a comparison filter is as follows.


In a comparison-based filter, the <filter> element has three properties:

  • The name attribute, which is the name of the filter.
  • The compare attribute, which contains the property that the filter evaluates.
  • The argument attribute, which is the argument against which the propertyName value is compared. If no argument is provided, null is used for comparison.

In the following example, if the PreferredRenderingType value is wml11, the filter matches.

    argument="wml11" />

When the filter is used in a <Choice> tag and the match in the filter is made, ASP.NET selects the device-specific content that is contained in the templates within the <Choice> element.

Evaluator-Delegate-Based Filters

Evaluator-delegate-based filters return true or false, depending on the processing that the method performs. The method computes the value of the return on any of the properties in the MobileCapabilities class. The returned value is used to determine whether the filter matches.

The syntax for an evaluator-delegate-based filter is as follows.


In an evaluator-delegate-based filter, there are three properties:

  • The name attribute, which is the name of the filter.
  • The type attribute, which is the class type that supplies the evaluator delegate. The name must follow the Microsoft .NET standards for specifying a fully-qualified type name. ASP.NET searches the specified assembly for the type.
  • The method attribute, which is the name of a method on class type that returns a Boolean value indicating whether the current device satisfies this filter based on the MobileCapabilities instance passed to it.

In the following example, if the IsGPSEnabled method returns true, the filter matches.


The following example is a skeleton declaration for the IsGPSEnabled method.


namespace MyApplication
    public class MyCapabilityEvaluators
        public static bool IsGPSEnabled(
            System.Web.Mobile.MobileCapabilities capabilities,
            String unusedArg)
            // Any necessary proccessing goes here.

After the code is compiled and the assembly is placed in a location where the application can access it, such as /bin, you can add support for it by adding a line to the <deviceFilters> section of Web.config. For example, if the previous filter were compiled into an assembly called MyApplication.dll, you would add the following line to the application.

<filter name="IsGPSEnabled"
   method="IsGPSEnabled" />

See Also

Extended Browser Capabilities | Device-Specific Rendering | <filter> Element

© 2015 Microsoft