How to retain dynamically created web server control - help !!

  • Thread starter Thread starter sydney.luu
  • Start date Start date
S

sydney.luu

Hello All,

I am programmatically building a table on my web page with one row and
two columns. The first column contains a web server checkbox
dynamically created and the second column simply contains text of
whatever I put in. This is running fine. If I check the checkbox, how
would I check if this checkbox is checked or not during postback? The
dynamically
created checkbox seems to have disappeared during postback.

Thanks in advance.
 
If you create a control programmatically, then when the page is reloaded you
must re-create it. If enableViewState is true and the id of the control is
the same, then it will be able to hook back up with its ViewState.
Peter
 
Thanks for responding. Do you have some references / links where I can
take a look at some examples of how this is done?
 
Got this to work. Thanks for the info.

Thanks for responding. Do you have some references / links where I can
take a look at some examples of how this is done?
 
I thought I had it working but not quite. When I enumerate through my
Repeater and evaluate which checkbox is checked, it always comes back
as being not checked on every row. Here's excerpt the code:

For Each rpItem In ViewRepeater.Items
chkRespFlag = CType(rpItem.FindControl("chkSel"), CheckBox)
If Not IsNothing(chkRespFlag) then
If chkRespFlag.Checked Then
intSelected += 1
Else
intNotSelected += 1
End If
End If
Next

My intSelected is always = 0. When I do a "View Source" on the brower,
I do see some of the rows do have chkSel.Checked = "Checked". Yet,
when I evaluate, it is telling they are not checked. Can someone
explain this?

Thanks.
 
Back
Top