how to retrieve control value from dynamically created controls

  • Thread starter Thread starter Dica
  • Start date Start date
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.
 
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
 
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.
 
Back
Top