Issue with Checkbox visible=false

I

icanhelp33

I have a checkbox in a web form. The initial value for visible for
this checkbox is false. On postback, depending on some criteria, the
visible property for this checkbox becomes true.
When action happens, I notice that the selected values for this
checkbox arent saved. Is this a bug. Is there a workaround.
 
P

Phil H

I have a checkbox in a web form. The initial value for visible for
this checkbox is false. On postback, depending on some criteria, the
visible property for this checkbox becomes true.
When action happens, I notice that the selected values for this
checkbox arent saved. Is this a bug. Is there a workaround.

If the "visible" property is set to false then the "checked" state
will not be saved. Normally, if a control has ViewStateEnabled set to
true then its settings are preserved between postbacks by embedding
state information in the code passed between server and client. If the
control is not visible and hence not rendered at all, then that state
information is discarded.

To get round it, you will need to use a Session variable created for
that purpose,
e.g. at an appropriate place in your code:
Session("YourCheckboxChecked") = YourCheckBox.Checked
YourCheckBox.Visible = false
 
A

Angel

to add to what Phil suggested you could try this as well

viewstate("mycheckboxvalue") = myCheckbox.checked


On postback say load event

myCheckbox.checked = ctype(myCheckboxvalue, boolean)


I find this more scalable than a session variable. Of course the issue of
scalability may be of no con
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top