Condividi tramite


Composite Controls

Both ASP.NET and ASP.NET mobile controls enable you to author new controls by combining existing controls. For example, if you want to encapsulate a number of mobile controls into one control, you can create a composite mobile control. You can create a composite control as a user control in an .ascx file, or as a custom control that is completely contained in a .dll.

Language Independence

You must author user controls in a single language, such as C# or Visual Basic. When you create a composite control, you can combine controls that have been created in different languages. For example, you can combine the C# CarControl example described in User Controls with a new control written in Visual Basic that inventories all cars with specified characteristics.

General Composition

Composite controls can inherit from any control class, including the mobile Web page MobileControl base class, or the mobile Web page Panel control class. For more information about inheritance, see Extending Functionality with Inheritance.

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

Using Composite Controls on a Mobile Web Page

After you create a composite mobile control, you can use it on a mobile Web page in these ways:

  • If the control is a user control, register the tag prefix, tag name, and .ascx file on the page with an @ Register directive, as shown in the following example:

    <%@ Register TagPrefix="myCompany" TagName="CarControl" Src="~/CarControl.ascx" %>

  • If the control is a custom control, register the tag prefix and assembly on the page using different syntax for the @ Register directive:

    <%@ Register TagPrefix="myComany" Namespace="company.MobileControls" Assembly="company.MobileControls" %>

Within the page, you can declaratively author the control into your page as in this example:

<myCompany:CarControl id="myCarCtl" runat="server" />

See Also

Concepts

User Controls

Device-Specific Composition

Writing Your Own Mobile Web Controls

Other Resources

Creating Custom Mobile Controls