Note that there are some explanatory texts on larger screens.

plurals
  1. POOnCheckedChanged event handler of asp:checkbox does not fire when checkbox is unchecked
    primarykey
    data
    text
    <p>I have a repeater, in each ItemTemplate of the repeater is an asp:checkbox with an OnCheckedChanged event handler set. The checkboxes have the AutoPostBack property set to true. When any of the checkboxes is checked, the event handler fires. When any is unchecked, the event handler does not fire.</p> <p>Any idea why the event does not fire, and how I mgiht make it fire? Thanks.</p> <p>Simplified repeater code:</p> <pre><code>&lt;asp:Repeater ID="rptLinkedItems" runat="server"&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox ID="chkLinked" runat="server" Checked="false" OnCheckedChanged="chkLinked_CheckedChanged" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:Repeater&gt; </code></pre> <p>The collection is bound to the repeater as follows:</p> <pre><code>protected override void OnPreRenderComplete(EventArgs e) { if (!Page.IsPostBack) { m_linkedItems = GetLinkedItems(); rptLinkedItems.DataSource = GetLinkableItems(); rptLinkedItems.ItemDataBound += new RepeaterItemEventHandler (rptLinkedItems_ItemDataBound); rptLinkedItems.DataBind(); } base.OnPreRenderComplete(e); } </code></pre> <p>The OnItemDataBound event handler is as follows:</p> <pre><code>private void rptLinkedItems_ItemDataBound(Object sender, RepeaterItemEventArgs args) { if (args.Item.ItemType == ListItemType.Item || args.Item.ItemType == ListItemType.AlternatingItem) { CategoryItem item = args.Item.DataItem as CategoryItem; Literal litItemName = args.Item.FindControl("litItemName") as Literal; CheckBox chkLinked = args.Item.FindControl("chkLinked") as CheckBox; litItemName.Text = item.Text; chkLinked.Checked = IsItemLinked(item); chkLinked.AutoPostBack = true; chkLinked.InputAttributes.Add("Value", item.Id.ToString()); } } </code></pre> <p>The OnCheckedChanged event handler is as follows:</p> <pre><code>protected void chkLinked_CheckedChanged(Object sender, EventArgs args) { CheckBox linkedItem = sender as CheckBox; Boolean itemState = linkedItem.Checked; Int32 itemId = Int32.Parse(linkedItem.InputAttributes["Value"].ToString()); DataAccessLayer.UpdateLinkedItem(m_linkingItem, Utilities.GetCategoryItemFromId(itemId), itemState); } </code></pre> <p>P.S. If someone can also tell me why markdown doesn't work correctly for me...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload