Share via


ASP.NET Device Filtering Overview

You can use device filtering to customize certain rendering aspects of Web server controls depending on the browser or device that accesses them. When a user requests a Web page from a server, the user's browser makes a request that contains information — such as the user-agent and other headers — that identifies the browser's type and version. ASP.NET can then match the identifier to a particular device that is defined in a browser file. And then output can be filtered by device by using the identifier in Web server controls.

Device Filtering

The following declarative code example demonstrates use of a device filter to shorten the text property of a Label control for a Pocket PC running Pocket Internet Explorer. This is a common use of a device filter, where more succinct text is provided for a device with limited screen size. The prefix "PIE" in front of the second Text attribute specifies that the control should render that version of the text if the requesting browser's identifier is "PIE".

<asp:Label runat="server" id="title" 
  Text="Welcome to Our Online Shopping Catalog"
  PIE:Text="Welcome, Shopper" />

Control Filters

You can filter output on controls for different devices by applying filters to the following:

  • Control properties

  • Custom attributes

  • Templates

Device Filters for Directives

You can also apply device filters to @ Page directive attributes to better suit device capabilities. For instance, you can disable view state for certain devices, or use different themes based on the device that is accessing the page. Some of the @ Page directives you can filter are:

  • Buffer

  • ClientTarget

  • CodePage

  • ContentType

  • Culture

  • EnableViewState

  • EnableViewStateMac

  • ErrorPage

  • LCID

  • MasterPageFile

  • ResponseEncoding

  • Theme

  • UICulture

If you are working with user controls, you can apply device filters to @ Control directive attributes as well. In general, the @ Control directive offers fewer attributes for which device filtering makes sense, but you could apply it to an attribute such as EnableViewState.

Finally, you can apply device-filters attributes, which are used to specify properties of a master page, in the @ Master directive.

Note

You cannot specify a device filter in the Web.config file.

See Also

Concepts

ASP.NET Mobile Web Development Overview