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

K

KK

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
 
M

Mike MacMillan

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top