Freigeben über


Introduction to Device Filters

Using device filters, applications can customize the appearance of controls for specific hardware devices or for categories of devices. The customization is based on the capabilities of the hardware device being used to browse the application.

For example, imagine that you are developing an application that will be used for a specific brand of handheld device that supports bitmap (.bmp) images. On this device, you want to display items in a List control with both text and an icon from a .bmp file. Using device filters, the application can detect that the request came from the target handheld device. This causes the application to use a device-specific template that displays list items with both text and an icon. This technique customizes the application for the specific hardware device.

Now imagine that you also want the application to be available on devices that display .gif images. Your application can apply device filters that detect when the request came from such a device. In that instance, the program specifies a template that displays list items with text and .gif images for its icons, rather than using .bmp images. This customizes the application for a category of devices.

Some other tasks that can be accomplished with device filters include:

  • Selecting styles based on the type of device.

  • Rendering controls with a richer presentation on devices that support it.

  • Rendering controls with a simpler presentation for devices with limited display capabilities.

Visual Studio stores device filters in the <deviceFilters> section of the application's Web.config file.

After a device filter is defined, applications can apply it to ASP.NET mobile controls to provide device-specific rendering. Device filters cannot be applied to container controls. However, they can be associated with container controls by attaching a DeviceSpecific control to a Form or Panel control. The designer translates filters applied in this way into <DeviceSpecific> markup language tags associated with the container control.

ASP.NET mobile controls support two types of device filters. The first type, called a comparison-based filter, compares a value that you specify to the current value of a device capability. Use this type of filter when you want to determine whether a device supports a specific capability.

The second type of device filter is called an evaluator or a delegate-based device filter. To perform the evaluation, this type of filter calls a method from a class that you create. Use evaluator filters when you need more complex device filtering than you can achieve with comparison-based filters.

Your application can define the method for the filter's evaluation either in a separate assembly or in the code-behind page. Device filters that use methods in code-behind files are not declared in the application's Web.config configuration file. If you define the method in the code-behind page, you must define it in the page that is derived from the System.Web.UI.MobileControls.MobilePage class.

See Also

Tasks

How to: Configure Device Filters

Concepts

Defining Device Filters

Applying Device Filters

Overriding Properties

Device-Specific Rendering

Other Resources

Customizing ASP.NET Mobile Web Controls for Specific Devices

Customizing with Control Templates