Control, Web Control and Composite Control

Discussion in 'ASP .Net' started by shapper, Dec 19, 2007.

  1. shapper

    shapper Guest

    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
     
    shapper, Dec 19, 2007
    #1
    1. Advertising

  2. System.Web.UI.Control is the base class for all ASP.Net Controls.
    System.Web.UI.WebControls.WebControl inherits Control, and is the base class
    for all ASP.Net WebControls. It contains a number of common properties and
    methods that are used by all WebControls. You would inherit this class when
    you want to employ some or all of those additional properties and methods.

    System.Web.UI.WebControls.CompositeControl is the base class for all
    WebControls that host other System.Web.UI.Controls. It is used when you want
    to composite a number of Controls into a single Control. It is a container
    which serves as the intermediary and coordinator of the Controls it
    contains. It implements INamingContainer, which is an interface that ensures
    that each Control has a unique ClientID, by combining their ID properties
    with the INamingContainer Control in which they are hosted.

    You probably want to create a CompositeControl. The following MSDN pages
    should help with this:

    http://msdn2.microsoft.com/en-us/library/zt27tfhy.aspx
    http://msdn2.microsoft.com/en-us/library/3257x3ea.aspx

    --
    HTH,

    Kevin Spencer
    Chicken Salad Surgeon
    Microsoft MVP

    "shapper" <> wrote in message
    news:...
    > 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
     
    Kevin Spencer, Dec 20, 2007
    #2
    1. Advertising

  3. shapper

    shapper Guest

    On Dec 20, 12:39 pm, "Kevin Spencer" <>
    wrote:
    > System.Web.UI.Control is the base class for all ASP.Net Controls.
    > System.Web.UI.WebControls.WebControl inherits Control, and is the base class
    > for all ASP.Net WebControls. It contains a number of common properties and
    > methods that are used by all WebControls. You would inherit this class when
    > you want to employ some or all of those additional properties and methods.
    >
    > System.Web.UI.WebControls.CompositeControl is the base class for all
    > WebControls that host other System.Web.UI.Controls. It is used when you want
    > to composite a number of Controls into a single Control. It is a container
    > which serves as the intermediary and coordinator of the Controls it
    > contains. It implements INamingContainer, which is an interface that ensures
    > that each Control has a unique ClientID, by combining their ID properties
    > with the INamingContainer Control in which they are hosted.
    >
    > You probably want to create a CompositeControl. The following MSDN pages
    > should help with this:
    >
    > http://msdn2.microsoft.com/en-us/li...dn2.microsoft.com/en-us/library/3257x3ea.aspx
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Chicken Salad Surgeon
    > Microsoft MVP
    >
    > "shapper" <> wrote in message
    >
    > news:...
    >
    > > 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


    I am having a problem here with Composite Control. It "wrappes" the
    controls in a Span Tag.
    Sure I can override the BeginTag but what I would like would to not
    render any tag at all.
    Just renders the controls inside the custom control.

    I was able to pull this by inheriting it from Control.
    So I have a Custom control, inheriting Control and Implementing
    INamingContainer, which contains various controls.
    This way it renders all child controls but without any wrapper tag.
    Is this ok?

    Thanks,
    Miguel
     
    shapper, Dec 20, 2007
    #3
  4. shapper

    bruce barker Guest

    sure, or if you want the composite control, just override RenderBeginTag and
    RenderEndTag and make them nop's.

    the main disadvantage of not using a span or div, is that the controls do
    not have a common parent in the dom, so absolute postioning will not work
    without client code to apply it to each element.

    -- bruce (sqlwork.com)


    "shapper" wrote:

    > On Dec 20, 12:39 pm, "Kevin Spencer" <>
    > wrote:
    > > System.Web.UI.Control is the base class for all ASP.Net Controls.
    > > System.Web.UI.WebControls.WebControl inherits Control, and is the base class
    > > for all ASP.Net WebControls. It contains a number of common properties and
    > > methods that are used by all WebControls. You would inherit this class when
    > > you want to employ some or all of those additional properties and methods.
    > >
    > > System.Web.UI.WebControls.CompositeControl is the base class for all
    > > WebControls that host other System.Web.UI.Controls. It is used when you want
    > > to composite a number of Controls into a single Control. It is a container
    > > which serves as the intermediary and coordinator of the Controls it
    > > contains. It implements INamingContainer, which is an interface that ensures
    > > that each Control has a unique ClientID, by combining their ID properties
    > > with the INamingContainer Control in which they are hosted.
    > >
    > > You probably want to create a CompositeControl. The following MSDN pages
    > > should help with this:
    > >
    > > http://msdn2.microsoft.com/en-us/li...dn2.microsoft.com/en-us/library/3257x3ea.aspx
    > >
    > > --
    > > HTH,
    > >
    > > Kevin Spencer
    > > Chicken Salad Surgeon
    > > Microsoft MVP
    > >
    > > "shapper" <> wrote in message
    > >
    > > news:...
    > >
    > > > 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

    >
    > I am having a problem here with Composite Control. It "wrappes" the
    > controls in a Span Tag.
    > Sure I can override the BeginTag but what I would like would to not
    > render any tag at all.
    > Just renders the controls inside the custom control.
    >
    > I was able to pull this by inheriting it from Control.
    > So I have a Custom control, inheriting Control and Implementing
    > INamingContainer, which contains various controls.
    > This way it renders all child controls but without any wrapper tag.
    > Is this ok?
    >
    > Thanks,
    > Miguel
    >
     
    bruce barker, Dec 20, 2007
    #4
  5. Hello

    > sure, or if you want the composite control, just override RenderBeginTag
    > and
    > RenderEndTag and make them nop's.

    Or simply overwrite the property "TagKey" and return the desired value.

    --
    Gruss, Peter Bucher
    Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
    http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
    http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET
     
    Peter Bucher [MVP], Dec 21, 2007
    #5
  6. That sounds like an excellent solution.

    --
    HTH,

    Kevin Spencer
    Chicken Salad Surgeon
    Microsoft MVP

    "shapper" <> wrote in message
    news:...
    > On Dec 20, 12:39 pm, "Kevin Spencer" <>
    > wrote:
    >> System.Web.UI.Control is the base class for all ASP.Net Controls.
    >> System.Web.UI.WebControls.WebControl inherits Control, and is the base
    >> class
    >> for all ASP.Net WebControls. It contains a number of common properties
    >> and
    >> methods that are used by all WebControls. You would inherit this class
    >> when
    >> you want to employ some or all of those additional properties and
    >> methods.
    >>
    >> System.Web.UI.WebControls.CompositeControl is the base class for all
    >> WebControls that host other System.Web.UI.Controls. It is used when you
    >> want
    >> to composite a number of Controls into a single Control. It is a
    >> container
    >> which serves as the intermediary and coordinator of the Controls it
    >> contains. It implements INamingContainer, which is an interface that
    >> ensures
    >> that each Control has a unique ClientID, by combining their ID properties
    >> with the INamingContainer Control in which they are hosted.
    >>
    >> You probably want to create a CompositeControl. The following MSDN pages
    >> should help with this:
    >>
    >> http://msdn2.microsoft.com/en-us/li...dn2.microsoft.com/en-us/library/3257x3ea.aspx
    >>
    >> --
    >> HTH,
    >>
    >> Kevin Spencer
    >> Chicken Salad Surgeon
    >> Microsoft MVP
    >>
    >> "shapper" <> wrote in message
    >>
    >> news:...
    >>
    >> > 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

    >
    > I am having a problem here with Composite Control. It "wrappes" the
    > controls in a Span Tag.
    > Sure I can override the BeginTag but what I would like would to not
    > render any tag at all.
    > Just renders the controls inside the custom control.
    >
    > I was able to pull this by inheriting it from Control.
    > So I have a Custom control, inheriting Control and Implementing
    > INamingContainer, which contains various controls.
    > This way it renders all child controls but without any wrapper tag.
    > Is this ok?
    >
    > Thanks,
    > Miguel
     
    Kevin Spencer, Dec 21, 2007
    #6
  7. shapper

    shapper Guest

    On Dec 20, 4:51 pm, bruce barker
    <> wrote:
    > sure, or if you want the composite control, just override RenderBeginTag and
    > RenderEndTag and make them nop's.
    >
    > the main disadvantage of not using a span or div, is that the controls do
    > not have a common parent in the dom, so absolute postioning will not work
    > without client code to apply it to each element.
    >
    > -- bruce (sqlwork.com)
    >
    > "shapper" wrote:
    > > On Dec 20, 12:39 pm, "Kevin Spencer" <>
    > > wrote:
    > > > System.Web.UI.Control is the base class for all ASP.Net Controls.
    > > > System.Web.UI.WebControls.WebControl inherits Control, and is the base class
    > > > for all ASP.Net WebControls. It contains a number of common properties and
    > > > methods that are used by all WebControls. You would inherit this class when
    > > > you want to employ some or all of those additional properties and methods.

    >
    > > > System.Web.UI.WebControls.CompositeControl is the base class for all
    > > > WebControls that host other System.Web.UI.Controls. It is used when you want
    > > > to composite a number of Controls into a single Control. It is a container
    > > > which serves as the intermediary and coordinator of the Controls it
    > > > contains. It implements INamingContainer, which is an interface that ensures
    > > > that each Control has a unique ClientID, by combining their ID properties
    > > > with the INamingContainer Control in which they are hosted.

    >
    > > > You probably want to create a CompositeControl. The following MSDN pages
    > > > should help with this:

    >
    > > >http://msdn2.microsoft.com/en-us/library/zt27tfhy.aspxhttp://msdn2.mi...

    >
    > > > --
    > > > HTH,

    >
    > > > Kevin Spencer
    > > > Chicken Salad Surgeon
    > > > Microsoft MVP

    >
    > > > "shapper" <> wrote in message

    >
    > > >news:...

    >
    > > > > 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

    >
    > > I am having a problem here with Composite Control. It "wrappes" the
    > > controls in a Span Tag.
    > > Sure I can override the BeginTag but what I would like would to not
    > > render any tag at all.
    > > Just renders the controls inside the custom control.

    >
    > > I was able to pull this by inheriting it from Control.
    > > So I have a Custom control, inheriting Control and Implementing
    > > INamingContainer, which contains various controls.
    > > This way it renders all child controls but without any wrapper tag.
    > > Is this ok?

    >
    > > Thanks,
    > > Miguel


    "sure, or if you want the composite control, just override
    RenderBeginTag and
    RenderEndTag and make them nop's. "

    What do you mean with nop's? Can you give me a sample code?

    Thanks,
    Miguel
     
    shapper, Dec 26, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sleigh
    Replies:
    1
    Views:
    2,705
    sleigh
    Feb 12, 2004
  2. rote
    Replies:
    0
    Views:
    407
  3. Chad
    Replies:
    0
    Views:
    236
  4. dave.dolan

    Generic Composite control (or any web control)

    dave.dolan, Aug 23, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    142
    dave.dolan
    Aug 23, 2006
  5. Mike

    Composite vs non composite Controls

    Mike, Mar 10, 2005, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    272
    Sundararajan
    Mar 11, 2005
Loading...

Share This Page