Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > this.Controls.Add(Control) Does Not Add Control to child collection (this.Controls.Count == 0)

Reply
Thread Tools

this.Controls.Add(Control) Does Not Add Control to child collection (this.Controls.Count == 0)

 
 
Chad Scharf
Guest
Posts: n/a
 
      10-16-2007
Ok, as silly as it may sound, I have a situation where I am creating a
CompositeControl in ASP.NET 2.0, C#. I have the following code in the
CreateChildControls() method that build the control's child control
collection:

for (int i = 0; i < _menus.Count; i++)
this.Controls.Add(_menus[i]);

foreach (FloatingMenu menu in _menus)
{
Label lbl = new Label();
lbl.ID = string.Concat("GroupQ", menu.ID);
lbl.CssClass = "menuItemGroupHeader";
lbl.Text = menu.GroupName;
this.Controls.Add(lbl);

HoverMenuExtender extender = new HoverMenuExtender();
extender.ID = string.Concat("ExtenderQ", menu.ID);
extender.TargetControlID = lbl.ID;
extender.PopupControlID = menu.ID;
extender.PopupPosition = HoverMenuPopupPosition.Bottom;
this.Controls.Add(extender);
}


The amazing thing is here, that the Label control and the HoverMenuExtender
AJAX Toolkit control both get added just fine, however I added a watch on
this.Controls.Count for the line where I add my FloatingMenu control
collection, "_menus", and after each call to "this.Controls.Add(_menus[i]);"
the Count is 0, however after I add the label it's 1 and the extender it's
2.

I'm stumped.

Thanks,
Chad


 
Reply With Quote
 
 
 
 
IfThenElse
Guest
Posts: n/a
 
      10-16-2007
What is the value of _menus.Count before the for loop


"Chad Scharf" <> wrote in message
news:%...
> Ok, as silly as it may sound, I have a situation where I am creating a
> CompositeControl in ASP.NET 2.0, C#. I have the following code in the
> CreateChildControls() method that build the control's child control
> collection:
>
> for (int i = 0; i < _menus.Count; i++)
> this.Controls.Add(_menus[i]);
>
> foreach (FloatingMenu menu in _menus)
> {
> Label lbl = new Label();
> lbl.ID = string.Concat("GroupQ", menu.ID);
> lbl.CssClass = "menuItemGroupHeader";
> lbl.Text = menu.GroupName;
> this.Controls.Add(lbl);
>
> HoverMenuExtender extender = new HoverMenuExtender();
> extender.ID = string.Concat("ExtenderQ", menu.ID);
> extender.TargetControlID = lbl.ID;
> extender.PopupControlID = menu.ID;
> extender.PopupPosition = HoverMenuPopupPosition.Bottom;
> this.Controls.Add(extender);
> }
>
>
> The amazing thing is here, that the Label control and the
> HoverMenuExtender AJAX Toolkit control both get added just fine, however I
> added a watch on this.Controls.Count for the line where I add my
> FloatingMenu control collection, "_menus", and after each call to
> "this.Controls.Add(_menus[i]);" the Count is 0, however after I add the
> label it's 1 and the extender it's 2.
>
> I'm stumped.
>
> Thanks,
> Chad
>



 
Reply With Quote
 
 
 
 
Chad Scharf
Guest
Posts: n/a
 
      10-17-2007
_menus.Count is 2 before the loop. And the second, foreach loop adds 2
Labels and 2 HoverMenuExtenders as it should. I tried the first loop with a
foreach initially, but remembering SyncRoot issues and thought perhaps the
enumerator was breaking the Add operation, I changed it to the for loop to
no avail.


"IfThenElse" <> wrote in message
news:%...
> What is the value of _menus.Count before the for loop
>
>
> "Chad Scharf" <> wrote in message
> news:%...
>> Ok, as silly as it may sound, I have a situation where I am creating a
>> CompositeControl in ASP.NET 2.0, C#. I have the following code in the
>> CreateChildControls() method that build the control's child control
>> collection:
>>
>> for (int i = 0; i < _menus.Count; i++)
>> this.Controls.Add(_menus[i]);
>>
>> foreach (FloatingMenu menu in _menus)
>> {
>> Label lbl = new Label();
>> lbl.ID = string.Concat("GroupQ", menu.ID);
>> lbl.CssClass = "menuItemGroupHeader";
>> lbl.Text = menu.GroupName;
>> this.Controls.Add(lbl);
>>
>> HoverMenuExtender extender = new HoverMenuExtender();
>> extender.ID = string.Concat("ExtenderQ", menu.ID);
>> extender.TargetControlID = lbl.ID;
>> extender.PopupControlID = menu.ID;
>> extender.PopupPosition = HoverMenuPopupPosition.Bottom;
>> this.Controls.Add(extender);
>> }
>>
>>
>> The amazing thing is here, that the Label control and the
>> HoverMenuExtender AJAX Toolkit control both get added just fine, however
>> I added a watch on this.Controls.Count for the line where I add my
>> FloatingMenu control collection, "_menus", and after each call to
>> "this.Controls.Add(_menus[i]);" the Count is 0, however after I add the
>> label it's 1 and the extender it's 2.
>>
>> I'm stumped.
>>
>> Thanks,
>> Chad
>>

>
>



 
Reply With Quote
 
Chad Scharf
Guest
Posts: n/a
 
      10-18-2007
Does anyone have any clue why this would happen? I'm still banging my head
against a wall trying to figure this out.

"Chad Scharf" <> wrote in message
news:%...
> Ok, as silly as it may sound, I have a situation where I am creating a
> CompositeControl in ASP.NET 2.0, C#. I have the following code in the
> CreateChildControls() method that build the control's child control
> collection:
>
> for (int i = 0; i < _menus.Count; i++)
> this.Controls.Add(_menus[i]);
>
> foreach (FloatingMenu menu in _menus)
> {
> Label lbl = new Label();
> lbl.ID = string.Concat("GroupQ", menu.ID);
> lbl.CssClass = "menuItemGroupHeader";
> lbl.Text = menu.GroupName;
> this.Controls.Add(lbl);
>
> HoverMenuExtender extender = new HoverMenuExtender();
> extender.ID = string.Concat("ExtenderQ", menu.ID);
> extender.TargetControlID = lbl.ID;
> extender.PopupControlID = menu.ID;
> extender.PopupPosition = HoverMenuPopupPosition.Bottom;
> this.Controls.Add(extender);
> }
>
>
> The amazing thing is here, that the Label control and the
> HoverMenuExtender AJAX Toolkit control both get added just fine, however I
> added a watch on this.Controls.Count for the line where I add my
> FloatingMenu control collection, "_menus", and after each call to
> "this.Controls.Add(_menus[i]);" the Count is 0, however after I add the
> label it's 1 and the extender it's 2.
>
> I'm stumped.
>
> Thanks,
> Chad
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen ASP .Net 1 05-18-2007 09:24 AM
Collection Not Saving Child Control Into Viewstate Chris A. ASP .Net Web Controls 0 05-16-2006 08:56 PM
Parent/Child relations - Trying to access child control for save tnt_lu@hotmail.com ASP .Net Datagrid Control 0 04-15-2005 12:50 PM
Placeholder child of child control event problem. caldera ASP .Net Building Controls 1 05-28-2004 07:56 AM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57