[thelist] .NET 2.0: Adding Multiple Controls

Casey Crookston caseyc at IntelliSoftmn.com
Thu Apr 12 08:22:52 CDT 2007


Ok, I'll give that a whirl.  On post back, if I re-create the first and
then create the second, will viewstate remember the values of each item?
One way to find out, I guess.  Should I be caching the user controls?

I'll go give this a shot and report back.

Casey

-----Original Message-----
From: Peter Brunone 


    Sounds like you're doing a postback each time, at which point the
controls you created during the previous postback are not remembered.

    What if you were to keep a record of how many new rows you have, and
loop to create that many plus one?

----------------------------------------

From: "Casey Crookston" caseyc at IntelliSoftmn.com

Ok, here's the (simple) concept:

A user will be manually entering rows of data. We don't know ahead of
time how many rows he'll be adding. Each row consists of a drop down, a
text field and a label. I have made a simple little user control which
contains these items. 

At the right time, the first instance of the control is added to a
placeholder. 

Sub AddLineItemRow()
ViewState("ItemCount") = ViewState("ItemCount") + 1
Dim ctlLineItems As Control =
LoadControl("admin_distribute_points_line_items.ascx")
ctlLineItems.ID = "ctlLineItems" & ViewState("ItemCount")
' populate drop down
plhLineItems.Controls.Add(ctlLineItems)
End Sub

Here's the catch. Outside of the control, I have a button with text
"Add New Row". When this button is clicked, we re-execute
AddLineItemRow(). This works, BUT, the previous row vanishes. In other
words, on the button click, a new Control is added with the ID of
ctlLineItems2, but ctlLineItems1 is gone. I need it to stay there.

What am I doing wrong. And, is there a better way to do this?

Thanks, Casey
-- 

* * Please support the community that supports you.  * *
http://evolt.org/help_support_evolt/

For unsubscribe and other options, including the Tip Harvester 
and archives of thelist go to: http://lists.evolt.org 
Workers of the Web, evolt ! 



More information about the thelist mailing list