Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Add to control collection recursively? or can class add itself?


Message #1 by "Chris Kersey" <ckersey@m...> on Mon, 17 Jun 2002 21:35:07 -0700
I'm creating a control where one class represents a link, and the other
class represents the control.  Both are derived from Webcontrol

My link class in it's basic form looks like this:

LinkId
ParentId //for a child link heirarchy
LinkName
LinkURL
protected override void Render()
...

The control class currently examines each row coming in from the datasource
for a parentid and then recursively checks the controls collection to see if
any of the already added controls contains a LinkId that matches the row's
parentId.  If so it adds the control as a child to that control in the
collection. (Side note: This works fine as is but still needs some added
logic for special cases.)

I'm wondering if it's possible/advisable to add a children collection and an
addchild method to the link class and have that class manage it's own
children.  Then the AddChild() method adds itself to the Controls collection
(Controls.Add(this)).  I haven't tried this method yet, but at face value it
seems like it might work, but I'm curious if it's off the "standard way of
doing things", or is duplicating the intent of the controls collection since
the controls collection contains a parent attribute.

Your comments and experience is appreciated.
Chris





  Return to Index