Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
The following is my code to generate multiple textboxes and drop down lists based on the value of the variable nov(also entered by user in a textbox).i want to add the values of the texbox to a string (convert the values to string and generate a sql create table query).on the button click i am losing all the values of the textboxes due to postback and i want to use an instance of viewstate to retain all the values entered by the user.





Public Sub display_table(ByVal nov As Int16)
For i As Integer = 1 To nov

Dim tb As New TextBox()
Dim tb2 As New DropDownList
Dim tb3 As New TextBox()

Dim tr As New TableRow()
Dim tc As New TableCell()
Dim tc2 As New TableCell()
Dim tc3 As New TableCell()
tb.ID = "txtName" + i.ToString()
tb.Width = 100
tb.Text = "Field Name" + i.ToString()
tb3.ID = "vv" + i.ToString()
tb3.Width = 100
tb3.Text = ""
tb2.ID = "dd" + i.ToString()
tb2.Width = 100
tb2.Text = "Datatype"
tb2.Items.Add("Int")
tb2.Items.Add("Varchar(20)")
tb2.Items.Add("Char(20)")
tblMain.Rows.Add(tr)
tr.Cells.Add(tc)
tc.Controls.Add(tb)


tc2.Controls.Add(tb2)

tr.Cells.Add(tc2)
tc3.Controls.Add(tb3)
tr.Cells.Add(tc3)

Next

End Sub
Posted

1 solution

The simplest way is to have a hidden control in your page and set its value to the concatenated values of all the dynamic controls before postback using JavaScript. On the server side, extract the value of the hidden control and use it as necessary.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900