简体   繁体   English

ASP.Net数据绑定控件未更新,可能是缓存问题?

[英]ASP.Net Databound control not updating, possible cache issue?

Working on a project with a setup like this: 使用这样的设置来处理项目:

  • ASPX Page ASPX页面
    • User Control 1 用户控制1
      • Radio Buttons 1-12 单选按钮1-12
    • User Control 2 用户控制2
      • Labels of values calculated off of Radio Buttons 1-12 通过单选按钮1-12计算得出的值的标签

Both UserControls are Databound, both have a "SaveData" method called from the ASPX page. 两个UserControl都是数据绑定的,都具有从ASPX页调用的“ SaveData”方法。

The values in UserControl2 are in Labels. UserControl2中的值在“标签”中。 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. 第一个是单击的单选按钮的编号(1到12),第二个是根据该编号计算的值。

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 repopulates. 重新填充UserControl时,标签仍然是旧值。

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. 但是,如果您按CTRL +刷新,则一切都会很好。

So obviously I've got an issue with the 2nd UserControl caching. 因此,显然第二个UserControl缓存存在问题。 How can I get around this and why doesn't the first UserControl (with Radio Buttons) cache? 我该如何解决这个问题,为什么第一个UserControl(带有单选按钮)不能缓存?

EDIT 编辑
While testing I added a TextBox bound to the same value as the RadioButton and the Label. 在测试时,我添加了一个文本框,该文本框绑定到与RadioButton和Label相同的值。 3 Controls, RadioButton using Bind on Field1, TextBox and Label using Eval on Field1 (but have tried Bind which also didn't work). 3个控件,在Field1上使用Bind的RadioButton,在Field1上使用Eval的TextBox和Label(但是已经尝试了Bind,但是也没有用)。
I changed the RadioButton from 1 to 3 and Saved. 我将RadioButton从1更改为3并保存。
On PostBack, RadioButton was correctly updated to 3. TextBox and Label both still said "1". 在PostBack上,RadioButton已正确更新为3。TextBox和Label都仍然表示为“ 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". 然后,我将RadioButton更改为6,并在TextBox中键入“ 4”(测试值的更改是否会强制更新,即使它是在EVAL而不是BIND上),然后单击“保存”。
On PostBack, RadioButton was correct at 6 but TextBox and Label both said "3". 在PostBack上,RadioButton正确为6,但TextBox和Label均表示为“ 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. 问题归结为以下事实:在DataBinding之后,在2个用户控件上单击按钮以调用“ SaveData”方法。 Calling "Form.DataBind" on the 2nd UserControl inside the "Save Data" method (or any time after the first UserControl has saved) fixes the issue. 在“保存数据”方法内(或在保存第一个UserControl之后的任何时间)在第二个UserControl上调用“ Form.DataBind”可解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM