ASP.Net Databound control not updating, possible cache issue?
Working on a project with a setup like this:
- ASPX Page
- User Control 1
- Radio Buttons 1-12
- User Control 2
- Labels of values calculated off of Radio Buttons 1-12
- User Control 1
Both UserControls are Databound, both have a "SaveData" method called from the ASPX page.
The values in UserControl2 are in Labels. The first is the number of the Radio button that was clicked (1 through 12), the 2nd is a value calculated based off that number.
When the page is Saved, the values are correctly saved and repopulated for the Radio Buttons. The labels are still the old values when the UserControl 开发者_StackOverflowrepopulates.
If you then put the cursor in the address bar and refresh, you have the same issue. But if you CTRL + Refresh, everything populates fine.
So obviously I've got an issue with the 2nd UserControl caching. How can I get around this and why doesn't the first UserControl (with Radio Buttons) cache?
EDIT
While testing I added a TextBox bound to the same value as the RadioButton and the Label. 3 Controls, RadioButton using Bind on Field1, TextBox and Label using Eval on Field1 (but have tried Bind which also didn't work). I changed the RadioButton from 1 to 3 and Saved. On PostBack, RadioButton was correctly updated to 3. TextBox and Label both still said "1". I then changed the RadioButton to 6 and typed "4" in the TextBox (testing if a change in value would force update even though it was on EVAL, not BIND) and hit "Save". On PostBack, RadioButton was correct at 6 but TextBox and Label both said "3".No idea what that means, but someone might make sense of that.
The issue comes down to the fact that the Button Click to call the "SaveData" methods on the 2 User Controls occurs AFTER the DataBinding. Calling "Form.DataBind" on the 2nd UserControl inside the "Save Data" method (or any time after the first UserControl has saved) fixes the issue.
精彩评论