I have a repeater control and each item/row has an asp:Checkbox control and a button next to it.
My problem is that if I check a given checkbox and click on the button next to it [before postback], the state (checked) of the previously checked Checkbox is preserved [after postback]. But I don't want it to be preserved so I've done the following for all the Checkboxes:
- Disabled the viewstate (EnableViewState='false') of the Checkboxes (and repeater)
- Defined the property Checked="false"
<td> <asp:CheckBox ID="chk_chooseTOL" CssClass="chk_chooseTOL" runat="server" Checked="false" EnableViewState="false" /> </td>
I looked at the state of the checkbox from the code-behind during the ItemDataBound event of the repeater in debugging mode, and it's fine, none of the checkboxes is checked, but at the end, the page is displayed and the previously checked checkbox remains checked. I don't understand why.
Do you have any idea how to not preserved the state of my checkboxes? (I need the check boxes to be server-side controls in order to disable them during the ItemDataBound event on a particular condition)
Thank you
Some more code :
<asp:Repeater ID="rpt_CA" runat="server" DataSourceID="TLDataSource" EnableViewState="false" OnItemDataBound="rpt_CA_OnItemDataBound" ClientIDMode="Static" >
<HeaderTemplate>
<table class="ca_table persist-area" id="rpt_CA">
<thead>
<tr class="tl-header persist-header">
<th>Consultant</th>
<th>Mode</th>
<th></th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label runat="server" Text='<%# Eval("EMPLOYEES.FULLNAME") + " (" + Eval("ID_EMPLOYEE") + ")" %>' />
</td>
<td>
<asp:Button runat="server" Text="Gen" EnableViewState="false" />
</td>
<td>
<asp:CheckBox ID="chk_chooseTOL" CssClass="chk_chooseTOL" runat="server" Checked="false" EnableViewState="false" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody>
</table>
</FooterTemplate>
</asp:Repeater>
.
protected void rpt_CA_OnItemDataBound(object Sender, RepeaterItemEventArgs Args) {
if (Args.Item.ItemType == ListItemType.Item || Args.Item.ItemType == ListItemType.AlternatingItem)
{ TURNOVER_LINES currentTL = (TURNOVER_LINES)Args.Item.DataItem; RepeaterItem ri = Args.Item;
CheckBox chk_chooseTOL = Args.Item.FindControl("chk_chooseTOL") as CheckBox;
if(currentTL.IS_ALREADY_GEN)
{
chk_chooseTOL.Enabled = false;
}
}
}
EnableViewState="False"
at repeater level? - Prashant Lakhlani