我在ASP.Net中构建了一个CompositeControl,现在在宿主页面上维护该控件的3个实例的ViewState时遇到了麻烦。我的CompositeControl有一个属性"HeaderText“,并且我的CompositeControl的所有3个实例都有页面上第一个控件实例的值。
例如:如果第一个控件的HeaderText =“Test1”,那么所有其他控件也都有HeaderText =“Test1”。
在调试过程中,我发现该属性的set操作符被调用了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"发布于 2016-05-03 21:25:38
以防其他人遇到这种情况:我打开了“外部代码”的调试,并发现我也意外地将该属性添加到了皮肤文件中。因此,HeaderText的集合运算符被称为2 times...hard以查找此错误。
https://stackoverflow.com/questions/37005485
复制相似问题