• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

How do I retrieve dynamically created form controls in the code behind?

On my page the user can select a number from a drop down list to choose how many text boxes to fill in. So, if the user selects 8, then 8 text boxes will be dynamically created at runtime and displayed on the page. I want to get the values that the user enters in these textboxes when the "submit" button is clicked, but I don't know how many textboxes have been created prior to runtime, so I don't know how many values there are. How do I get these values in the codebehind?
0
CitySec
Asked:
CitySec
1 Solution
 
the_billCommented:
You could say, if the user has selected n from the drop down list, create controls and assign them IDs
txtDynamicBox1, up to txtDynamicBoxn.

You would then get each dynamic textbox, by going through a for loop, and use FindControl to get the textbox eg

For i as Integer = 1 to DropdownPicker.Text
Dim myTextBox as TextBox
 myTextBox = FindControl("txtDynamicBox" & i)
Next

Just ensure your code to generate the boxes isnt filtered for non-postbacks only, ie dont create the boxes in a If IsPostBack=False statement
0
 
darshan_derasariCommented:
Go through below links which explain concept of dynamic controls.


http://forums.asp.net/t/1186195.aspx
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now