This documentation is archived and is not being maintained.

Implementing a Web Forms Template Editor

.NET Framework 1.1

A template editor is a special-purpose designer that supports template creation and editing for a templated ASP.NET server control. A control with a template editor presents a design surface onto which a page developer can drag controls from the toolbox to create inline templates. The DataList and DataGrid server controls in the .NET Framework SDK are examples of controls that support template editing. For information about authoring a templated control, see Developing a Templated Control.

The .NET Framework provides an abstract base class (System.Web.UI .Design.TemplatedControlDesigner) that derives from ControlDesigner and exposes properties and methods needed for template editing. A template editor must derive from TemplatedControlDesigner. The following procedure describes the key steps in implementing a template editor.

To implement a template editor

  1. Define a class that derives from TemplatedControlDesigner.
  2. Override the AllowResize property inherited from ControlDesigner to enable the control to be resized. It is recommended that controls allow resizing when in template mode even if they normally do not allow resizing.
  3. Override the GetCachedTemplateEditingVerbs method. A control overrides this method to return the list of template editing verbs applicable to the control. See step 4 for a description of a template editing verb.
  4. Override the CreateTemplateEditingFrame method. This method takes a TemplateEditingVerb instance as an argument. TemplateEditingVerb is a designer verb (a class that derives from DesignerVerb) that enables the template editor to add a command to the control at design time. For background information about designer verbs, see Designer Verbs.
  5. Override the GetTemplateContent method that gets the template content.
  6. Override the SetTemplateContent method that sets the template content.
  7. As with any other designer, override the GetDesignTimeHtml, GetEmptyDesignTimeHtml, and GetErrorDesignTimeHtml methods inherited from the ControlDesigner class. If the templated control is data-bound, the overridden GetDesignTimeHtml method must set the data source of the control to the design-time data source, as described in Implementing a Web Forms Data-Bound Control Designer.

    If the templated control is data-bound, you must also implement the steps described in Implementing a Web Forms Data-Bound Control Designer and override the following additional methods of TemplatedControlDesigner (described in steps 8 and 9).

  8. Override the GetTemplateContainerDataSource method to provide the data source of the template container. This is called from the data-binding dialog box when editing the data bindings of controls placed within a template.
  9. Override the GetTemplateContainerDataItemProperty method to access the name of the DataItem property of the template container.

For a sample of a template editor, see the Web Forms Templated Data-Bound Control Designer Sample.

See Also

Web Forms Templated Data-Bound Control Designer Sample | Implementing a Web Forms Data-Bound Control Designer | Custom Designers | Design-Time Support for Web Forms

Show: