Control, WebControl and CompositeControl

Last post 12-19-2007 10:46 PM by Mercury082. 4 replies.

Sort Posts:

  • Control, WebControl and CompositeControl

    12-19-2007, 4:25 PM
    • Contributor
      3,569 point Contributor
    • shapper
    • Member since 11-28-2004, 9:15 PM
    • Posts 2,947

    Hello,

    I am working in a class library with various custom controls.

    In which cases should a control inherit Control, WebControl and CompositeControl classes?

    And when should a custom control implement INamingContainer?

    In this moment I am working on a custom control that is composed by a TextBox, a Label, two Validator controls and a button.

    I don't want it to render a tag around these controls. Should I, in this case, inherit it from Composite Control? And do I need to implement INamingContainer?

    Thanks,

    Miguel

     

     

  • Re: Control, WebControl and CompositeControl

    12-19-2007, 9:11 PM
    • Participant
      980 point Participant
    • Mercury082
    • Member since 04-23-2007, 6:57 PM
    • Posts 156

    In situations where your custom control contains multiple controls you should inherit from CompositeControl. If you inherit from CompositeControl you will get INamingContainer for free. INamingContainer is a marker interface that is used to identify a container control that creates a new ID namespace within a page's control hierarchy. Basically this ensures each of the controls inside your composite control will have a unique client id. You can override the Render* method/s in your custom control to create markup exactly how you want it.

  • Re: Control, WebControl and CompositeControl

    12-19-2007, 9:50 PM
    • Contributor
      3,569 point Contributor
    • shapper
    • Member since 11-28-2004, 9:15 PM
    • Posts 2,947

    Yes,

    I know that. But notice that when inheriting from Composite Control you will always get a tag wrapping the controls in it.

    The default is <span> and by using RenderBeginTag I can get any other.

    If I am not wrong, the only way to not have the wrapper tag is by inhering from control.

    I am using Control and I added Implement INamingContainer ... I think it solves the naming issue, right?

    Thanks,

    Miguel 

  • Re: Control, WebControl and CompositeControl

    12-19-2007, 9:55 PM
    Answer
    • Contributor
      3,569 point Contributor
    • shapper
    • Member since 11-28-2004, 9:15 PM
    • Posts 2,947

    Yes,

    I know that. But notice that when inheriting from Composite Control you will always get a tag wrapping the controls in it.

    The default is <span> and by using RenderBeginTag I can get any other.

    If I am not wrong, the only way to not have the wrapper tag is by inhering from control.

    I am using Control and I added Implement INamingContainer ... I think it solves the naming issue, right?

    Thanks,

    Miguel 

  • Re: Control, WebControl and CompositeControl

    12-19-2007, 10:46 PM
    • Participant
      980 point Participant
    • Mercury082
    • Member since 04-23-2007, 6:57 PM
    • Posts 156

    Yep, that solves the naming issue.

Page 1 of 1 (5 items)