how to retrieve control value from dynamically created controls

D

Dica

i've got a script that creates a new tablerow + tablecell and appends that
to a non dynamically created table control. a new row is added for each
recordset returned from my sql statement. within each tablecell, i place a
dynamically created checkbox control. i now need to fetch back the value of
the checkbox as follows:

foreach (Control c in tblServices.Controls) {
}

this doesn't work, however. if i step through with the debugger, the only
controls listed under tblServices are the tablerows, not the checkbox.

how do i navigate down to the checkbox control so i can fetch the value?

tks.
 
E

Eliyahu Goldin

2 points:

1. You need to re-create dynamically created controls on every postback,
preferably in Page_Init event.

2. Controls property contains only immediate children. You need to drill
down row-cell-checkbox.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
D

Dica

Eliyahu Goldin said:
2 points:

1. You need to re-create dynamically created controls on every postback,
preferably in Page_Init event.

2. Controls property contains only immediate children. You need to drill
down row-cell-checkbox.

thanks, eliyahu. i suspected it was something like that. i was expecting to
be able to get directly to the control but as you said, i had to drill down,
which i accomplished with a nested for loop.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Dica said:
i've got a script that creates a new tablerow + tablecell and appends
that to a non dynamically created table control. a new row is added for
each recordset returned from my sql statement. within each tablecell, i
place a dynamically created checkbox control. i now need to fetch back
the value of the checkbox as follows:

foreach (Control c in tblServices.Controls) {
}

this doesn't work, however. if i step through with the debugger, the only
controls listed under tblServices are the tablerows, not the checkbox.

how do i navigate down to the checkbox control so i can fetch the value?

tks.
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top