【问题标题】:Problems with ViewState of CompositeControlCompositeControl的ViewState问题
【发布时间】:2016-08-28 13:53:01
【问题描述】:

我在 ASP.Net 中构建了一个 CompositeControl,现在我无法在托管页面上维护该控件的 3 个实例的 ViewState。我的 CompositeControl 有一个属性“HeaderText”,我的 CompositeControl 的所有 3 个实例都具有页面上第一个控件实例的值。

例如:如果第一个控件有 HeaderText = "Test 1",那么所有其他控件也有 HeaderText = "Test 1"。

在调试过程中,我发现该属性的集合运算符被调用了 2 次。当我使用 Debug.WriteLine() 输出跟踪集合运算符时,输出如下所示:

HeaderText of Control 1 = "Test 1"
HeaderText of Control 2 = "Test 2"
HeaderText of Control 3 = "Test 3"
HeaderText of Control 1 = "Test 1" <-- Why is the set operator called 2 times for each Control?
HeaderText of Control 2 = "Test 1"
HeaderText of Control 3 = "Test 1"

【问题讨论】:

    标签: asp.net viewstate composite-controls


    【解决方案1】:

    以防万一其他人遇到这种情况:我打开了“外部代码”的调试,发现我不小心也将属性添加到了皮肤文件中。因此 HeaderText 的集合运算符被调用了 2 次...很难找到这个错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-11
      • 1970-01-01
      相关资源
      最近更新 更多