get value of dynamically added controls

W

wapsiii

I have a form to which I add sets of input controls ie. textbox 1,
dropdownlist 1, textbox 2, dropdownlist 1, textbox 3, dropdownlist 3.
The number of sets vary.

I give them unique IDs the following way: txt_1, ddl_1, txt_2, ddl_2,
txt_3, ddl_3.

When the form is submitted I retrieve the values of the dynamically
added controls by iterating over the request.form collection looking
for IDs txt_ and ddl_

Is there a better way to retrieve the values?

Morten
 
G

Guest

For a known ID? no.

Even if you loop through controls, you will still have to match the values
to the IDs. Now, there is a potential of creating a hashtable to store names
and values at the same time you create the control and matching changed
values. If you can then pass this to a database as a "parameter collection",
you are golden. Realize, however, that this ease of "coding" can be murder on
performance with all of the boxing and unboxing that goes on.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
W

wapsiii

I see. So I should create some type of collection (arraylist), add the
IDs of the dynamically created controls as string properties to an
object. Add the objects to the collection. Then add the collection to
a session variable and then, when the form is submitted, reverse the
process: casting the session variable to the collection, and iterating
the collection of objects getting every ID and simply use the IDs to
precisely query reguest.form?
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top