extended Label webcontrol, doesn't populate it's children ??

Discussion in 'ASP .Net Web Controls' started by KK, Dec 23, 2005.

  1. KK

    KK Guest

    Hi,

    I am extending couple of existing controls in ASP.NET
    like LinkButton, Label, TextBox etc..

    I require these controls to contain a child control of MyControlType
    so ideally in HTML view for a label

    <asp:Label id="" [other properties...] >
    <cc1:MyControlType id="" [other properties...] />
    <cc1:MyControlType id="" [other properties...] />
    <cc1:MyControlType id="" [other properties...] />
    </asp:Label>

    this kind of a thing should happen. So all my extended classes are
    decorated with PArseChildren(false, <Property>)

    It works fine for LinkButton. when I check LinkButton.Controls it
    now has the MyControlType populated. However, for a Label it doesn't
    work. Whenever i include a MyControlType within the label, Label's TEXT
    property gets empty and controls.count remains ZERO. Why ?

    Is this by design? (which means I won't be able to have nested controls for
    Label, TextBox etc.. ?)

    Any help is appreciated

    KK
    KK, Dec 23, 2005
    #1
    1. Advertising

  2. KK,
    first, the label control's text property is set during the
    AddParsedSubObject method internally...and only LiteralControl's are
    used to populate the .Text property, hence the .Text property being
    zero'd out.
    second, it is possible to nest controls within a label, such as:
    <asp:Label id="lblFoo" runat="server">
    <asp:Textbox id="txtFoo1" runat="server"/>
    <asp:Textbox id="txtFoo2" runat="server"/>
    </asp:Label>

    since you're using a custom control namespace, do you have
    runat="server" on each tag? if so, what html source is being rendered,
    if any, between the <span></span> tags for the label?

    it sounds like you need exact control over what controls are children
    of the label. since you cannot change the behavior of the stock label
    control while still referencing it as asp:label, i would recommend
    writing your own custom control. for example, if you built a custom
    control that derived from Label, you could override the
    AddParsedSubObject method which will give you strict control as to how
    it handles the controls it parses. if you need even further support,
    you could even write your own ControlBuilder to allow parsing custom
    tags.

    let me know if you're still having issues,
    Mike MacMillan



    KK wrote:
    > Hi,
    >
    > I am extending couple of existing controls in ASP.NET
    > like LinkButton, Label, TextBox etc..
    >
    > I require these controls to contain a child control of MyControlType
    > so ideally in HTML view for a label
    >
    > <asp:Label id="" [other properties...] >
    > <cc1:MyControlType id="" [other properties...] />
    > <cc1:MyControlType id="" [other properties...] />
    > <cc1:MyControlType id="" [other properties...] />
    > </asp:Label>
    >
    > this kind of a thing should happen. So all my extended classes are
    > decorated with PArseChildren(false, <Property>)
    >
    > It works fine for LinkButton. when I check LinkButton.Controls it
    > now has the MyControlType populated. However, for a Label it doesn't
    > work. Whenever i include a MyControlType within the label, Label's TEXT
    > property gets empty and controls.count remains ZERO. Why ?
    >
    > Is this by design? (which means I won't be able to have nested controls for
    > Label, TextBox etc.. ?)
    >
    > Any help is appreciated
    >
    > KK
    Mike MacMillan, Dec 28, 2005
    #2
    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. avnrao
    Replies:
    1
    Views:
    664
    =?Utf-8?B?dG9ueQ==?=
    May 13, 2004
  2. Stefaan V.

    How to serialize an extended property for a Webcontrol?

    Stefaan V., Oct 7, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    142
    Stefaan V.
    Oct 7, 2004
  3. KK
    Replies:
    1
    Views:
    107
    Mike MacMillan
    Dec 28, 2005
  4. Enjoy Life
    Replies:
    2
    Views:
    256
    Roland Hall
    Feb 23, 2005
  5. Knut Krueger
    Replies:
    8
    Views:
    251
    Knut Krueger
    Aug 20, 2013
Loading...

Share This Page