locked
How to render composite control inside DIV tag RRS feed

  • Question

  • User-825949172 posted

    By default composite controls render inside SPAN tag.

    Like custom controls derived from WebControl can be rendered inside any choose HTML tag, is it same possible for custom controls derived from CompositeControl?

    Saturday, August 30, 2008 3:57 PM

Answers

  • User-874886737 posted

    Try adding this code (I'm using VB.NET):

            Protected Overrides ReadOnly Property TagKey() As System.Web.UI.HtmlTextWriterTag
                Get
                    Return HtmlTextWriterTag.Div
                End Get
            End Property

    This is also better for W3C validation.

    Jos

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 31, 2008 3:30 AM

All replies

  • User-874886737 posted

    Try adding this code (I'm using VB.NET):

            Protected Overrides ReadOnly Property TagKey() As System.Web.UI.HtmlTextWriterTag
                Get
                    Return HtmlTextWriterTag.Div
                End Get
            End Property

    This is also better for W3C validation.

    Jos

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 31, 2008 3:30 AM
  • User481221548 posted

    Hi there

    There are two ways:

    1. Override TagKey as Jos described
    2. Put the TagKey in the base constructor

    Its also possible to override RenderBegin- and RenderEndTag, but the two ways shown above are the best and cleanly ones.

    Sunday, August 31, 2008 11:11 PM
  • User-825949172 posted

     I found what Jos says useful. However you cannot put TagKey in the base contructor when you derive your custom control from compositecontrol. This can be achived when deriving from WebControl.

    Monday, September 1, 2008 8:00 AM