Browse DevX
Sign up for e-mail newsletters from DevX


Build Your Own Mobile Controls

The mobile controls provided with ASP.NET are often insufficient. When that happens, a custom, from-scratch direct control is what you need. This article explains the ASP.NET mobile rendering model and guides you through the process of building your own custom mobile control.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

hat was once known as the Mobile Internet Toolkit is now ASP.NET mobile controls. It's the only Microsoft technology that enables you to target multiple devicesѿincluding Palm devices, Pocket PCs, WAP phones, etc. More than 200 devices and emulators are supported.

Here's how it works: A single application or Web page with multiple controls renders itself automatically based on the client device. As a developer you only need to write one code base. ASP.NET's mobile technology, called the Adaptive Rendering Model, manages the complexity of device proliferation for you.

In this article I'll show you how to create your own direct control from scratch, but first it is important to understand the architecture of the ASP.NET Adaptive Rendering Model. There are three parts that function together to enable rendering to multiple devices: The ASP.NET mobile controls, the device adapter, and the device adapter definition.

Mobile Controls: These are the same types of controls that'd you'd find in standard ASP.NET, including buttons, labels, and text boxes, but designed specifically for handheld devices with small displays.

Device Adapter: Roughly equivalent to device drivers in Windows, device adapters' job is to generate output from a control. There are various device adapters that are grouped by families that map to markup languages such as HTML 3.3, cHTML, WML (1.1 and 1.2), and XHTML.

Device Adapter Definition: It maps between devices, controls, and device adapters.

These three parts work together in the rendering process. Figure 1 shows a page, Mobile.aspx, with a PhoneCall control. A PhoneCall control when viewed from a mobile phone allows a person to make a call by clicking on the control. However, when a user from a web page accesses it, it just displays alternate-text specified in the control. When a user with a WAP mobile phone accesses the page via a WAP gateway, the MobileCapabilities class is used by the rendering mechanism to determine the browser and the device. Then the page instantiates the control and an appropriate device adapter is selected; in this case the WML Adapter is used, so WML is returned to the device. When that process is complete, the user can dial the phone number specified in the phone call control.

Figure 1. The PhoneCall Control: The MobileCapabilities class determines what device driver to instantiate so that a phone call can be made by clicking the control.
Figure 2. Pocket PC: In the Pocket PC version of the .aspx page from Figure 1, the mobile framework provides the alternate text, as specified for this device when a PhoneCall control is encountered.

Author's Note: The MobileCapabilities class is built on the standard browser capabilities feature of ASP.NET. It a single source for accessing capability information about a client device and for performing queries against device capabilities.

In Figure 2 a Pocket PC device is accessing the same page. The same steps are repeated, however Pocket PCs do not support making phone calls. ASP.NET invokes the HTML device adapter and returns the alternate-text specified in the control to the user via HTML. This is the specified action for the Pocket PC with this control.

It is important to note that the .aspx page is compiled only once but depending on the device accessing the page, different adapters are used. Microsoft provides a Mobile Application Architecture animated presentation of this entire rendering model.

Thanks for your registration, follow us on our social networks to keep up-to-date