Retaining Checkbox values during postback (ASPX)

  • Thread starter Thread starter Scott H
  • Start date Start date
S

Scott H

I have a page with several server controls placed on there at design
time, including a blank table control.

During runtime I add some controls to the table, including some
checkboxes, which I called ch() as checkbox. the user would then
check some of them and click a button.

the event handler for the button would save the checkbox checked state
to a database.
but as soon as the button is clicked, ch() is nothing. all the other
design time controls have retained their values, but not the
checkboxes.

Scott
 
First, do these checkboxes have EnableViewState=True? Do all of their parent
Controls have EnableViewState=True? If they do, you can try adding some code
to the Page.Load event that reads the checked state from the database so
that each time the page loads it sets the checked state to whatever the user
selected the last time. If you don't want to have to go to the trouble of
reading from the database, you could use Cookies or Session variables and
only worry about reading the database for long-term purposes, it all depends
on exactly what your site is used for. If you need help figuring out how to
do any of these things feel free to ask. Good Luck!
 
Back
Top