I had a Repeater
with ViewState
disabled and several input controls with ViewState
enabled. After I would postback and rebind the data based off of various selections the INPUT
controls didn't update. They kept the same state they had before the postback.
To elaborate if my filter was X and I had two inputs, the first one in state X1 and the second one in state X2. If I switched my filter to Y the inputs would be still in state X1 and X2 respectively.
Turning ViewState
on fixed this. My question is why? I excluded most of the code because it was boiler plate. You can bind a list of integers to the Repeater
and then if the integer was odd or even and set the Checkbox
to that value it would function as my boiler plate code did/does.
Below is pseudocode.
<asp:repeater EnableViewState="false">
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<asp:checkbox runat="server" id="foo" EnableViewState="True">
</ItemTemplate>
</asp:repeater>
The EnableViewState
property will override any child controls which in your case you are trying to enable.
See 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.
and
The ViewStateMode property for the control is set to Enabled or inherits the Enabled setting.
So having the Repeater
's EnableViewState
property set to false
is forcing all your child controls to also be set to false regardless of you indicating at the control level that you want it to be true
.