Implementing Templated Rendering

ASP.NET mobile controls that support templated rendering also support a default rendering. Decisions on how templates are used to put together rendering can vary depending on the target device. ASP.NET provides a standard sequence of operations that allow templated rendering to be device-specific. Mobile controls that support templated rendering must use the following sequence:

  1. The control determines whether device templates are defined and selected, using the IsTemplated property. Use the OnInit method or the CreateChildControls method to do this.

  2. If templates are defined, the control calls the CreateTemplatedUI method, which the control inherits from the MobileControl base class.

    Note

    Do not call CreateTemplatedUI if the control is not templated.

  3. CreateTemplatedUI calls the control adapter's CreateTemplatedUI method. You can code device adapters that override this method to implement device-specific templated rendering.

  4. The default implementation of the control adapter's CreateTemplatedUI method, which is defined in the control adapter base class, in turn calls the control's CreateDefaultTemplatedUI method. You can code controls that override this method to implement general templated rendering.

  5. In the adapter's Render method, the control renders templates by rendering the control's child (where instances of templates are created).

Mobile controls also must always create instances of new templates inside a container control type derived from TemplateContainer. This is a stricter rule than the rule for ASP.NET server controls, which requires only that the control implement the INamingContainer marker interface. The following code example shows how to create an instance of a template in a mobile control.

void CreateChildTemplate(ITemplate template)
{
    TemplateContainer container = new TemplateContainer();
        template.InstantiateIn(container);
        container.DataBind();
        Controls.Add(container);
}

ItemCommand Events

With templated rendering, the ItemCommand event handler is called through the ASP.NET event-bubbling mechanism. The event handler is passed a parameter that points to the source item and to the CommandName property of the control that generated the event. This allows you to render a single list item with multiple associated interactions.

On default rendering, the control provides a simple user interface that allows the user to click a list of items. On postback, the control calls the ItemCommand handler with an argument pointing to the source item. The CommandName property returns a null.

See Also

Tasks

How to: Create Templated ASP.NET User Controls

Concepts

Template Sets and Templated Controls

Other Resources

Adding New Device Adapters and Device Support