Selecting Page and Control Adapters


We said earlier that each control has an associated set of adapters responsible for rendering different kinds of markup. Let’s look a little more closely at what this means.

When a MobilePage executes, it examines the headers in the HTTP request to determine the capabilities of the requesting browser. In the browserCaps section of the configuration file, a set of regular expressions is applied to headers, starting with the User-Agent string. When a matching expression is found, the default browser capabilities are overridden by the values specified by that match. Often a matching regular expression will cause a set of nested regular expressions to execute to further define specific browser capabilities, which allows you to detect and handle variations between device models and browser versions. When the regular expression does not match, the associated capability settings and nested matches will not be applied for that browser type.

After this preliminary information about the browser is gathered, the page can select an adapter to handle page framework behavior specific to the page being executed. Perhaps it’s more accurate to express this in reverse by saying that a page adapter selects itself. The page adapters expose a method configured as the DeviceQualifies predicate in machine.config or web.config files. The DeviceQualifies code is tasked with ascertaining whether it can render for the capabilities of the requesting device. The DeviceQualifies methods are executed in the order they appear in the configuration until one returns true, essentially selecting itself to manage the current request. The page adapter is responsible for managing view state, postback data, and postback handlers; for providing the appropriate TextWriter for handling page output; and for selecting adapters for the controls contained in the page. The page adapter participates in the page life cycle events and delegates to the adapters as well.

In the machine.config file, you’ll notice that adapters are grouped into adapter families, with a page adapter as the parent that contains a set of compatible control adapters. These control adapters are used to render the output and process events for the associated control.

The concept of the control tree is essentially duplicated in the adapter hierarchy. The page control contains a set of child controls, and each mobile control has an associated adapter. The adapters can create child controls to produce the user interface appropriate for the functionality of the associated server control on a specific device. Page events such as OnInit, OnLoad, OnPreRender, and OnUnload can be handled by the adapter or left for the control to manage.




Microsoft ASP. NET Coding Strategies with the Microsoft ASP. NET Team
Microsoft ASP.NET Coding Strategies with the Microsoft ASP.NET Team (Pro-Developer)
ISBN: 073561900X
EAN: 2147483647
Year: 2005
Pages: 144

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net