Dynamically Creating Controls On A Page

E

epigram

I'm dynamically creating a number of radio buttons on my aspx page based
upon data read from a db. Each radio button has autopostback turned on.
I'm experiencing two problems.

1) I am reading the db, creating the radio buttons, and setting the checked
property (also based upon data in the db) in Page_Load regardless of whether
a postback is occurring or not. The page loads and displays correctly each
time unless the database is updated (say by another program). In this
situation, even though I'm creating the radio buttons and setting their
checked property based on the db, it appears that whatever is in the
viewstate is overriding this process. So, whatever was on the user's screen
before posting back is what gets displayed after the postback regardless of
what is currently in the db. I'd like to know how to overcome this.

2) In this same situation (when the db gets updated) I do get a
CheckedChanged event not only for the change the user made (that caused the
postback to occur) but for any differences between db values and their
corresponding radio button's checked status. This, I suppose, is expected
but is difficult to understand given problem #1. The problem is if I
blindly take each CheckedChanged event and update the db with the current
value of the radio button (as it was on the user's screen) I'll almost
always overwrite changes made by another user. Is the typical approach here
an optimistic locking scheme with a row counter of some type to use to
prevent me from updating "stale" data?

This seems overly complicated, so I assume my approach is wrong. Any help
would be much appreciated. Thanks!
 
W

Wouter van Vugt

Hi,

could you tell me at what stage in the page lifecycle you are loading
your database data. The Viewstate and postback data are loaded in
between the Init and Load stage (signalled by the events). So if you
load your data in the Init stage....

Grtz, Wouter van Vugt
Trainer - Info Support - www.infosupport.com
www.dive-in-it.nl
 

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,009
Latest member
GidgetGamb

Latest Threads

Top