JavaScript Editor jscript editor     Web designer 

Main Page

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 defined in a browser file. Output can then 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 LabelfrlrfSystemWebUIWebControlsLabelClassTopic 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".

В CopyCode imageCopy Code
<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:

  • 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 in the @ Master directive used to specify properties of a master page.


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

See Also

JavaScript Editor jscript editor     Web designer