viewstate = false doesn't work

D

Dica

i've got a simple page with a dropdown list of employees and a series of
checkboxs showing their skills. the checkboxs are created dynamically from a
sql statement and viewstate = false is set on each one. once the dropdown
changes from one employee to another, the checkboxes are all recreated and i
check the database to see if that particular employee has that skill. if so,
i set the checkbox's checked state to true. however, when i look at the
newly rendered page, the only checkboxs that are checked are those that i've
manully checked. i could set the viewstate in the page directive, but that
applies to all controls and i want the page to remember which employee was
last selected.

so, it looks like my script is initializing the checkboxes to the correct
value initially, but after that .net steps in and sets them back to what was
last posted even though i've set viewstate to all checkbox controls to
false.

anybody got any ideas what i'd doing wrong here?

tks
 
P

Patrice

Field values are not stored in the viewstate. By design a web page post
field values to the server. The viewstate was created to store other values.
So IMO your controls are just reinitialized from postback values.

Double check your code. You likely forgot to initialize the values from the
db after a postback ( it's likely that usually you don't bind again on a
postback because the data are what you want to show but in this particular
case the postback change the current set of data you wan't to display so you
should bind again to your data).
 
D

Dica

Patrice said:
Field values are not stored in the viewstate. By design a web page post
field values to the server. The viewstate was created to store other
values. So IMO your controls are just reinitialized from postback values.

yes. that's exactly what i'm seeing. what i'm trying to do is stop the asp
net engine from repopulating these fields based on the posted back data and
instead use the values i'm assigning as the dynamically created controls are
initialized. i modified my page so that when the user drop down list is
changed (causing a postback event) i capture the selected user to session
and then response.redirect back to the same page. then, within page_load i
get the selected user and call my routine to recreate the dynamic controls
with the appropriate values. this works fine. so, it's something in the
postback event i need to control, but how? if the solution is to rebind my
data, in which event handler should it go? in other words, which event would
fire after .net is done repopulating the form fields?

tks
 

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,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top