我有一个禁用了 ViewState
的 Repeater
和几个启用了 ViewState
的输入控件。在我根据各种选择回发并重新绑定(bind)数据后,INPUT
控件没有更新。它们保持回发前相同的状态。
详细说明我的过滤器是否为 X 并且我有两个输入,第一个输入处于状态 X1,第二个输入处于状态 X2。如果我将过滤器切换到 Y,输入仍将分别处于状态 X1 和 X2。
打开ViewState
修复了这个问题。我的问题是为什么?我排除了大部分代码,因为它是样板。您可以将整数列表绑定(bind)到Repeater,然后如果整数是奇数或偶数并将Checkbox
设置为该值,它将像我的样板代码一样运行/确实如此。
下面是伪代码。
<asp:repeater EnableViewState="false">
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<asp:checkbox runat="server" id="foo" EnableViewState="True">
</ItemTemplate>
</asp:repeater>
最佳答案
EnableViewState
属性将覆盖您尝试启用的任何子控件。
参见MSDN :
Gets or sets a value indicating whether the server control persists its view state, and the view state of any child controls it contains, to the requesting client.
和
The ViewStateMode property for the control is set to Enabled or inherits the Enabled setting.
因此,将 Repeater
的 EnableViewState
属性设置为 false
会强制所有子控件也设置为 false,无论您如何在控制级别表明您希望它为true
。
关于asp.net - 中继器 View 状态不刷新输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25288145/