OnCheckedChanged event handler of asp:checkbox does not fire when checkbox is unchecked

Try usingAutoPostBack="true" like this:

<asp:CheckBox ID="chkLinked" runat="server" Checked="false"
    OnCheckedChanged="chkLinked_CheckedChanged" AutoPostBack="true"/>

This is because the control hierarchy (and the check boxes in particular) don't exist when ASP.NET executes the Control events portion of the ASP.NET page life cycle, as you had created them in the later PreRender stages. Please see ASP.NET Page Life Cycle Overview for more detailed overview of the event sequence.

I would err on the side of caution for @bleeeah's advice, for you're assigning a value to CheckBox.Checked inside rptLinkedItems_ItemDataBound, which would also cause the event handler to execute:


chkLinked.Checked = IsItemLinked(item);

Instead, move:


if (!Page.IsPostBack)
   {
      m_linkedItems = GetLinkedItems();
      rptLinkedItems.DataSource = GetLinkableItems();
      rptLinkedItems.ItemDataBound += new RepeaterItemEventHandler
          (rptLinkedItems_ItemDataBound);
      rptLinkedItems.DataBind();
   }

Into the Page.Load event handler.


Try re-subscribing to the CheckChanged event in your OnItemDataBound event ,

chkLinked.CheckedChanged += new EventHandler(chkLinked_CheckedChanged);

Tags:

C#

Asp.Net

C# 2.0