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

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.
 
G

Guest

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
 
S

sydney.luu

Thanks for responding. Do you have some references / links where I can
take a look at some examples of how this is done?
 
S

sydney.luu

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?
 
S

sydney.luu

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.
 

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,774
Messages
2,569,596
Members
45,142
Latest member
DewittMill
Top