Composite Controls

ASP.NET class composition provides a technique whereby you can author new controls by combining existing controls. This technique also works for ASP.NET mobile controls. For example, if you want to encapsulate a number of mobile controls into one control, you can create a composite mobile control. Composite controls are equivalent to user controls that are authored using ASP.NET page syntax. The key difference between a composite control and a user control is that a user control is persisted as an .ascx text file, whereas a composite control is compiled and persisted in an assembly file (.dll). For detailed information about creating composite controls, see the Web Forms topic Developing a Composite Control

Language Independence

Although you must author individual user controls in a single language, such as C#, when you create a composite control, you can combine controls that are written in a variety of languages. For example, you can combine the C# CarCtl example described in the User Controls documentation with a new control written in Visual Basic that inventories all cars with specified characteristics that exist in a car dealership.

General Composition

Composite controls can inherit from any control class, including the ASP.NET server control Control base class (System.Web.UI), the mobile Web Forms MobileControl base class, or the mobile Web Forms Panel control class. However, by inheriting from either of the latter two classes, the control can act as a first-class mobile control on the page. For more information about inheritance, see Extending Functionality with Inheritance.

Adapters for the MobileControl and Panel classes render child controls by default, and thus provide the necessary adapter support for composite controls. If the control inherits from any other mobile control, you must provide an adapter that renders the child controls.

Composite Control Deployment

After you create a composite mobile control, you deploy it by compiling it into an assembly, such as *myCompany.*MobileControls.dll. You then register the assembly on a page by using the @ Register directive in a custom tag, as shown in the following example.

[C#]

// Insert this section in a Mobile Web Forms page.
<%-- Registers the myCompany.MobileControls namespace. --%>
<%@ Register TagPrefix="myCompany" TagName="CarCtl" Namespace="myCompany.MobileControls" Assembly="myCompany.MobileControls" %>

    // Insert other code here.

    <%-- Control declaration -->
    <myCompany:CarCtl id="myCarCtl" runat="server" />

See Also

User Controls | Extend Functionality with Inheritance | Device-Specific Composition | Writing Your Own Controls