Consecutive Additions of Controls

M

Matthew MacDonald

Hi all,
I'm trying to make a web form that will allow the user to continuously add
options to a form by clicking a button.

Here is my sample code.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim drop As New DropDownList



tblMain.Rows(13).Cells(1).Controls.Add(drop)

End Sub

I want this to keep adding new drop down lists to the table whenever the
user clicks the button. What happens, however, is that the page reloads and
only one new control is ever added to the page (or more exactly, the
previous new control is wiped out and a new one is added, thus only ever
having one)


Any ideas on this??

Thanks, Matt
 
B

bruce barker

you have to re-add dynamic controls on postback, so you will need to
remember that you added them.

-- bruce (sqlwork.com)
 
K

Karl

Tables don't maintain their state in postback. You can track how often a
row has been added in viewstate and add that amount:

dim count as integer = 0
if not ViewState("RowCount") is nothing then
count = cint(viewstate("RowCount"))
end

count += 1
for i as iteger = 0 to count
'ADD row
next
viewstate("RowCount") = count

Karl
 
M

Matthew MacDonald

OK, that all makes sence. The problem however is that the controls
(specificaly dropdownlists) that have been added will probably have user
selections in them. When I add another one, I want the users selections for
the first controls to be maintained. I'm sure I could keep track of all of
this, but there has got to be a better way. Can you push a stack or que
onto the session or something like that?

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top