Chapter 22: Programming Device Adapters and Building Controls from Scratch
Overview
Chapter 20 and Chapter 21, you learned how to build user controls and how to build custom controls in code by inheritance and by composition. User controls are easy to build and employ. Custom controls can be quite simple to build using inheritance or composition, and these controls rarely require you to create new device adapter classes.If you want complete control over the functionality of a custom control, however, you should build it from scratch by inheriting from a base class, such as System.Mobile.UI.MobileControl. This technique presents challenges you will not encounter when using other forms of custom controls. You need to understand the interactions between a control class, which implements the methods and properties of a mobile control and defines the control as the application developer views it, and device adapter classes, which implement device-specific behavior of the control such as rendering the markup that is sent to the client. It also requires an in-depth knowledge of the markup languages the devices use.
In this chapter, you'll come to understand the life cycle of a mobile control. You'll learn how to program device adapter classes to render a control and implement its device-specific logic. You'll see how to build a custom control from scratch by inheriting from the MobileControl class and implementing device adapter classes to render the user interface. You'll discover how to build controls that support data binding, handle ViewState, cause postback from the client to the server, and support templates. Also, you'll see how to implement a custom System.Web.UI.MobileControls. MobileControlBuilder object that allows you to parse ASP.NET server control syntax from an .aspx file.