Writing Your Own Controls

Writing your own controls provides the greatest measure of flexibility. You can create a significantly original ASP.NET mobile control that inherits directly from the MobileControl base class or differs substantially from its parent class. However, development of original mobile controls must adhere to some basic guidelines:

  • Write your mobile control so that it inherits from the MobileControl base class and not from an ASP.NET Control class. The MobileControl base class inherits all the applicable capability from the ASP.NET Control class that is necessary to ensure successful development for wireless devices. However, to reuse the logic from a ASP.NET server control, you can use containment to include the control in a mobile control.
  • Write your control so that the code itself is device-independent.
  • Write device-specific adapters for each device type that requires a different type of rendering for the control.
  • Design reusable code so that other developers can inherit properties and methods from your control.
  • For a detailed example of writing your own control, see the following Mobile Quick Starts Sample

Custom Persistence

ASP.NET server controls can implement customized persistence formats (syntax) by using their own control builder. You can enable this by creating a control builder class, and then adding a ControlBuilder attribute to the class. You use control builder objects when a page is parsed and compiled.

The MobileControl base class has its own control builder, the MobileControlBuilder class. All mobile controls that implement their own control builder must have the control builder inherit from the MobileControlBuilder class. The following table lists control classes that implement their own control builder.

Control class Control builder class
DeviceSpecific DeviceSpecificControlBuilder
Form FormControlBuilder
List ListControlBuilder
MobileControl MobileControlBuilder
ObjectList ObjectListControlBuilder
Panel PanelControlBuilder
StyleSheet StyleSheetControlBuilder

If a control inherits from one of the controls in the preceding table and needs to implement custom persistence, it must use a class that inherits from the ControlBuilder base class.

See Also

Implementing Custom Persistence