|
 |
aspx thread: RE: Dynamically creating LiteralControls in a custom W ebControl.
Message #1 by kevin.burton@i... on Fri, 1 Dec 2000 21:09:25 -0600
|
|
That is a good idea and it seems to be working. But now I have run into
another roadblock. I want to insert an array of controls. A node (with the
details removed) looks like:
<LI>
<IMG/>
<A/>
<UL>
(I want to insert here)
</UL>
</LI>
When this is done it will essentially be a TreeView of the data where I only
expand the nodes that are clicked on.
When the tree is first built it will only have a single node. When the user
clicks on the node I want to query a database and insert the array of nodes
into the the ilst betwen the <UL> opening and closing tag. Since everything
is a LiteralControl there does not seem to be an "insert" method in the
ControlCollection members. Also I have not been able to get a hierarchy
built that works so that I could merely insert the newly expanded tree into
the 'Controls' member of the <UL> literal control. Any suggestions as to how
I might do that?
Thank you.
Kevin Burton
kevin.burton@i...
-----Original Message-----
From: Joe Jones [mailto:joejo@m...]
Sent: Thursday, November 30, 2000 10:54 AM
To: ASP+
Subject: [aspx] RE: Dynamically creating LiteralControls in a custom W
ebControl.
Not that I am aware of, since the controls collection seems to be just an
array. If you need to index the collection, you might want to store the
ordinal value in your post back string parameter.
Joe
> -----Original Message-----
> From: kevin.burton@i... [mailto:kevin.burton@i...]
> Sent: Wednesday, November 29, 2000 3:59 PM
> To: ASP+
> Subject: [aspx] RE: Dynamically creating LiteralControls in a
> custom W ebControl.
>
>
> I the RasePostBackEvent can I search the 'Controls'
> collection for a particular item by name? If I can do that
> then how do I change that item?
>
> I have implemented a LoadPostData (right now I just return
> false) and I set a break point there and I notice that it
> never gets called. Should it be called. I put the
> NonComposition2.cs/.aspx files into the debugger and I notice
> that the
> LoadPostData routine is getting called. What determines
> whether this is called or not?
>
> Thanks again.
>
> Kevin Burton
> kevin.burton@i...
>
>
> -----Original Message-----
> From: Joe Jones [mailto:joejo@m...]
> Sent: Wednesday, November 29, 2000 1:09 PM
> To: ASP+
> Subject: [aspx] RE: Dynamically creating LiteralControls in a
> custom W ebControl.
>
>
> The only information you get is the string parameter you pass
> to GetPostBackEventReference as the second param. I usually
> encode what ever info I need into this string,and then decode
> it in the RaisePostBackEvent event handler.
>
> Joe
>
> > -----Original Message-----
> > From: kevin.burton@i... [mailto:kevin.burton@i...]
> > Sent: Wednesday, November 29, 2000 9:45 AM
> > To: ASP+
> > Subject: [aspx] RE: Dynamically creating LiteralControls in a
> > custom W ebControl.
> >
> >
> > Thank you, I had missed this example. This will be very helpfull.
> >
> > Now, what information is available to me about the object or
> > control that was clicked on? I don't quite understand the use
> > of LoadPostData and the arguments passed in to that function.
> > Is what I want to do is to modify the class name of one of
> > the literal controls so that its children will be hidden or
> > exposed. I also want to modify the image to reflect a
> > collapsed or expanded list. So I need to a) know which
> > control in the array of controls that I have created that was
> > clicked on, b) modify the contents of the control and/or
> > insert a new array of controls (if this node has not been
> > expanded before).
> >
> > Any ideas?
> >
> > Kevin Burton
> > kevin.burton@i...
> >
> >
> > -----Original Message-----
> > From: Joe Jones [mailto:joejo@m...]
> > Sent: Wednesday, November 29, 2000 10:46 AM
> > To: ASP+
> > Subject: [aspx] RE: Dynamically creating LiteralControls in a
> > custom WebCo ntrol.
> >
> >
> > You have to implement IPostBackEventHandler in your Control.
> >
> > There is a sample that shows how to do this. If you've
> > installed the samples, you can see the examples at:
> >
> > http://localhost/quickstart/util/srcview.aspx?Path=/quickstart
> > /aspplus/sampl
> > es/webforms/ctrlauth/noncomposition/NonComposition2.src&file=N
> > onComposition2
> > .cs
> >
> > (Watch out for wrapped URLs)
> >
> > Joe
> >
> > > -----Original Message-----
> > > From: kevin.burton@i...
> [mailto:kevin.burton@i...]
> > > Sent: Tuesday,
> November 28, 2000 11:29 AM
> > > To: ASP+
> > > Subject: [aspx] Dynamically creating LiteralControls in a custom
> > > WebControl.
> > >
> > >
> > > I am trying to build a custom control that essentially is
> a TreeView
> > > of my data. I have been able to build a control that uses
> Render...
> > > and builds a tree of child controls in CreateChildControls. These
> > > two methods work just fine. Now I want to dynamically build the
> > > tree. When I click on a node if the content for the node has not
> > > been retrieved I want to retrieve it and build the
> content otherwise
> > > I want to just expand or contract the list. The expanding and
> > > contracting I will do by changing the classid of the list
> along with
> > > a .CSS file. To build a the content for a node I need to
> intercept a
> > > 'click' event and insert the content. My question is how do I
> > > intercept a 'click' event and process it on the server?
> And how do I
> > > figure out what item I clicked on and modify the
> LiteralControl tree
> > > structure to include the new information?
> > >
> > > Any suggestions would be greatly appreaciated.
> > >
> > > Kevin Burton
> > > kevin.burton@i...
> > >
> > >
> >
>
Message #2 by Joe Jones <joejo@m...> on Mon, 4 Dec 2000 10:20:58 -0800
|
|
Not sure if I understand you completely, but...
When you click an item in the treeview, you should be generating a postback
event to your server side control. This will cause you to regenerate all the
content in that control. However, this happens BEFORE you get the post back
event handler (@*$&&!).
Now, In my control, I am using a HtmlTable inserted into the Control's
Controls collection. Since this is the only control I add, I can get the 0th
item in my postback handler, cast it to an HtmlTable and use the HtmlTable's
Rows and Cells collections to do what I need.
For you, I would think about the following. Split the SubControl creation
out into a separate function. Then, in the the CreateChildControls function,
check the Control's IsPostBack param to see if it is true. If not, call your
creation function. If so, then postpone this until you get into your
postback handler, and THEN create your child controls.
Hope this helps.
Joe
> -----Original Message-----
> From: kevin.burton@i... [mailto:kevin.burton@i...]
> Sent: Friday, December 01, 2000 7:09 PM
> To: ASP+
> Subject: [aspx] RE: Dynamically creating LiteralControls in a
> custom W ebControl.
>
>
> That is a good idea and it seems to be working. But now I
> have run into another roadblock. I want to insert an array of
> controls. A node (with the details removed) looks like: <LI>
> <IMG/>
> <A/>
> <UL>
> (I want to insert here)
> </UL>
> </LI>
>
> When this is done it will essentially be a TreeView of the
> data where I only expand the nodes that are clicked on.
>
> When the tree is first built it will only have a single node.
> When the user clicks on the node I want to query a database
> and insert the array of nodes into the the ilst betwen the
> <UL> opening and closing tag. Since everything is a
> LiteralControl there does not seem to be an "insert" method
> in the ControlCollection members. Also I have not been able
> to get a hierarchy built that works so that I could merely
> insert the newly expanded tree into the 'Controls' member of
> the <UL> literal control. Any suggestions as to how I might do that?
>
> Thank you.
>
> Kevin Burton
> kevin.burton@i...
Message #3 by kevin.burton@i... on Tue, 5 Dec 2000 16:46:25 -0600
|
|
I am trying to do the following in CreateChildControls
// Create the parent control
Controls.Add(new LiteralControl("<LI>"));
// Add the <IMG> control to the list
Controls.Add(new LiteralControl("<IMG OnClick=\"jscript:" +
Page.GetPostBackEventReference(this, _system) + "\" " + "WIDTH=\"16\"
SRC=\"images/bs.gif\"/>"));
// Add the <A> control to the list
Controls.Add(new LiteralControl("<A TITLE=\"" + _system + "\">" +
_system + "</A>"));
// Create the <UL> control
Controls.Add(new LiteralControl("<UL>"));
Controls.Add(new LiteralControl("</UL>"));
Controls.Add(new LiteralControl("</LI>"));
The problem is in the RaisePostBackEvent handler I have a signature like:
public void RaisePostBackEvent(String eventArgument)
Assuming that the 'Controls' structure is still global, how should I encode
the index of the <IMG> control (so I can change the image) and the <UL>
control so I can insert the new data, ie. the list of the directory nodes
below the node clicked on. I am not sure what you mean by the "other" item
in the postback handler. When I get a postback event isn't the Controls
structure still intact? Won't it still have the data that I populated it
with in CreateChildControls? Are you saying that CreateChildControls will
get called each time a postback occurs? Ahhh, I had not considered that. So
if I modify my CreateChildControls to do something like:
if(!IsPostBack())
{
// Create the parent control
Controls.Add(new LiteralControl("<LI>"));
// Add the <IMG> control to the list
Controls.Add(new LiteralControl("<IMG OnClick=\"jscript:" +
Page.GetPostBackEventReference(this, _system) + "\" " + "WIDTH=\"16\"
SRC=\"images/bs.gif\"/>"));
// Add the <A> control to the list
Controls.Add(new LiteralControl("<A TITLE=\"" + _system +
"\">" + _system + "</A>"));
// Create the <UL> control
Controls.Add(new LiteralControl("<UL>"));
Controls.Add(new LiteralControl("</UL>"));
Controls.Add(new LiteralControl("</LI>"));
}
But I still have the problem that I need to "insert" a list of data. If the
directory looks like:
A
a
b
c
B
C
When I first come up I will see
A
B
C
If I click on A I need to insert the 'a b c' into the list. So the HTML will
come out like:
<LI>
<IMG/> (for the 'A' node)
<A/>
<UL>
<LI>
<IMG/> (for the 'a' node)
<A/>
<UL>
</UL>
</LI>
<LI>
<IMG/> (for the 'b' node)
<A/>
<UL>
</UL>
</LI>
<LI>
<IMG/> (for the 'c' node)
<A/>
<UL>
</UL>
</LI>
</UL>
</LI>
How do I get at the control to insert these additional controls so the HTML
is rendered as above? I have tried to use the 'Controls' member of the each
of the LiteralControls to try to build a hierarchy but the sub items are not
rendered.
Thanks again for your assistance.
Kevin Burton
kevin.burton@i...
-----Original Message-----
From: Joe Jones [mailto:joejo@m...]
Sent: Monday, December 04, 2000 12:21 PM
To: ASP+
Subject: [aspx] RE: Dynamically creating LiteralControls in a custom W
ebControl.
Not sure if I understand you completely, but...
When you click an item in the treeview, you should be generating a postback
event to your server side control. This will cause you to regenerate all the
content in that control. However, this happens BEFORE you get the post back
event handler (@*$&&!).
Now, In my control, I am using a HtmlTable inserted into the Control's
Controls collection. Since this is the only control I add, I can get the 0th
item in my postback handler, cast it to an HtmlTable and use the HtmlTable's
Rows and Cells collections to do what I need.
For you, I would think about the following. Split the SubControl creation
out into a separate function. Then, in the the CreateChildControls function,
check the Control's IsPostBack param to see if it is true. If not, call your
creation function. If so, then postpone this until you get into your
postback handler, and THEN create your child controls.
Hope this helps.
Joe
> -----Original Message-----
> From: kevin.burton@i... [mailto:kevin.burton@i...]
> Sent: Friday, December 01, 2000 7:09 PM
> To: ASP+
> Subject: [aspx] RE: Dynamically creating LiteralControls in a
> custom W ebControl.
>
>
> That is a good idea and it seems to be working. But now I
> have run into another roadblock. I want to insert an array of
> controls. A node (with the details removed) looks like: <LI>
> <IMG/>
> <A/>
> <UL>
> (I want to insert here)
> </UL>
> </LI>
>
> When this is done it will essentially be a TreeView of the
> data where I only expand the nodes that are clicked on.
>
> When the tree is first built it will only have a single node.
> When the user clicks on the node I want to query a database
> and insert the array of nodes into the the ilst betwen the
> <UL> opening and closing tag. Since everything is a
> LiteralControl there does not seem to be an "insert" method
> in the ControlCollection members. Also I have not been able
> to get a hierarchy built that works so that I could merely
> insert the newly expanded tree into the 'Controls' member of
> the <UL> literal control. Any suggestions as to how I might do that?
>
> Thank you.
>
> Kevin Burton
> kevin.burton@i...
|
|
 |