Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Anybody build a hierarchical ControlCollection?


Message #1 by kevin.burton@i... on Wed, 29 Nov 2000 14:04:52 -0600
I was reading in "A Preview of Active Server Pages+" about creating a user

defined (custom) Web Control. From those examples I started to build my own

custom ASP.NET control. Taking their advice I used 'LiteralControls' and

other "controls" to build the page in CreateChildControls rather than output

raw HTML in a Render function. This worked just fine. Now since this is a

TreeView control I felt that it would be better to build a hierarchy of

controls rather than the flat approach of using Contols.Add(...). The tree

uses '<LI>' to describe each node and '<UL>' to contain the child nodes. So

I have:



   list = new LiteralControl("<LI>");

   img = new LiteralControl("<IMG WIDTH=\"16\" SRC=\"images/bs.gif\"/>");

   anchor = new LiteralControl("<A TITLE=\"" + d.Name + "\">");

    text = new LiteralControl(d.Name);



    Controls.Add(list);

    Controls.Add(img);

    Controls.Add(anchor);

    Control.Add(text);



     anchor = new LiteralControl("</A>");

     sublist = new LiteralControl("<UL>");



     control.Add(anchor);

     control.Add(sublist);



     _Directory(sublist.Controls, d);



     sublist = new LiteralControl("</UL>");

     list = new LiteralControl("</LI>");



I have not listed the _directory routine but it is much like the above, just

creating appropriate '<LI>' and '<UL>' tags based on the type of file in the

directory. The problem is that when I use '_Directory(sublist.Controls, d)'

I don't get the child nodes rendered. When I use '_Directory(Controls, d)' I

get the child nodes displayed but now I am back to a flat array of all of

the controls. Is this a bug or am I doing something wrong?



Kevin Burton

kevin.burton@i...




  Return to Index