|
 |
aspx thread: Building a hierarchy or controls.
Message #1 by kevin.burton@i... on Wed, 6 Dec 2000 11:40:12 -0600
|
|
I am trying to build a TreeView WebControl. I have started out by building a
flat list of 'LiteralControls' for each of the node objects. I quickly
realized that I will need to insert lists into the hierarchy so a
one-dimensional array will not do. In other words I cannot use just the
Controls array I need utilize the Controls member of each control to insert
child controls in order to build this hierarchy. I will have something like:
LiteralControl list;
list = new LiteralControl("<LI></LI>");
list.Controls.Add(new LiteralControl("<IMG></IMG>"));
list.Controls.Add(new LiteralControl("<A></A>");
sublist = new LiteralControl("<UL></UL>");
list.Controls.Add(sublist);
sublist.Controls.Add(new LiteralControl("<LI></LI>");
.
.
Controls.Add(list);
etc. . . .
The problem is that it seems that the child controls do not seem to get
renered. Looking at the documentation I notice that there is a protected
members "HasControls" and "ChildControlsCreated" and "EnsureChildControls"
and "RenderChildren". I have not set any of that up so am I right to assume
that if I want to have child controls I have to build my own class? In my
case this class would be something like TreeNode. Are there any examples or
hints as to how I would go about developing a user defined WebControl that
has custom controls in it?
Thank you.
Kevin Burton
kevin.burton@i...
Message #2 by kevin.burton@i... on Wed, 13 Dec 2000 18:03:46 -0600
|
|
I seemed to have found the answer to my problem. If I do the following the
hierarchy is preserved:
HtmlGenericControl list = new HtmlGenericControl("LI");
HtmlImage image = new HtmlImage();
image.Src = "images/dc.gif"
image.Width = 16;
list.Controls.Add(image);
HtmlAnchor anchor = new HtmlAnchor();
anchor.Title = "Title";
anchor.InnerText = "InnerText";
list.Controls.Add(anchor);
HtmlGenericControl sublist = new HtmlGenericControl("UL");
....
list.Controls.Add(sublist);
(etc.) . . .
This is very helpful because now I can build a hierarchy of controls. Now I
need to be able to respond to the ServerClick event. I want to be able to
respond the a ServerClick event for HtmlImage but it does not seem to have
that as part of its member functions. Does anyone have some example code
where I can respond to a click event on the server? How would I add this to
the HtmlImage control? The effect I want is to change the image when it is
clicked on simulating an expanded or collapsed list (like a TreeView
control). If you can see a better ay to do this I would appreciate any
suggestions.
Thank you.
Kevin Burton
kevin.burton@i...
-----Original Message-----
From: kevin.burton@i... [mailto:kevin.burton@i...]
Sent: Wednesday, December 06, 2000 11:40 AM
To: ASP+
Subject: [aspx] Building a hierarchy or controls.
I am trying to build a TreeView WebControl. I have started out by building a
flat list of 'LiteralControls' for each of the node objects. I quickly
realized that I will need to insert lists into the hierarchy so a
one-dimensional array will not do. In other words I cannot use just the
Controls array I need utilize the Controls member of each control to insert
child controls in order to build this hierarchy. I will have something like:
LiteralControl list;
list = new LiteralControl("<LI></LI>");
list.Controls.Add(new LiteralControl("<IMG></IMG>"));
list.Controls.Add(new LiteralControl("<A></A>");
sublist = new LiteralControl("<UL></UL>");
list.Controls.Add(sublist);
sublist.Controls.Add(new LiteralControl("<LI></LI>");
.
.
Controls.Add(list);
etc. . . .
The problem is that it seems that the child controls do not seem to get
renered. Looking at the documentation I notice that there is a protected
members "HasControls" and "ChildControlsCreated" and "EnsureChildControls"
and "RenderChildren". I have not set any of that up so am I right to assume
that if I want to have child controls I have to build my own class? In my
case this class would be something like TreeNode. Are there any examples or
hints as to how I would go about developing a user defined WebControl that
has custom controls in it?
Thank you.
Kevin Burton
kevin.burton@i...
To unsubscribe send a blank email to leave-aspx-$subst('Recip.MemberIDChar')@p2p.wrox.com
---
You are currently subscribed to aspx as: $subst('Recip.EmailAddr')
To unsubscribe send a blank email to leave-aspx-$subst('Recip.MemberIDChar')@p2p.wrox.com
|
|
 |