title: ASP.NET - Control Events Not Firing Inside Repeater
body: <p>This is a absurdly common issue and having exhausted all of the obvious solutions, I'm hoping SO can offer me some input... I have a UserControl inside a page which contains a repeater housing several controls that cause postback. Trouble is, all of the controls inside of the repeater never hit their event handlers when they postback, but controls outside of the repeater (still in the UC) are correctly handled. I already made sure my controls weren't being regenerated due to a missing <code>if(!IsPostBack)</code> and I verified that Request.Form["__EVENTTARGET"] contained the correct control ID in the Page_Load event. I attempted to reproduce the symptoms in a separate project and it worked as it should.</p>
  
  <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="NoteListControl.ascx.cs"
      Inherits="SantekGBS.Web.UserControls.NoteListControl" %&gt;
  
  &lt;asp:UpdatePanel ID="upNotes" runat="server" UpdateMode="Conditional"&gt;
      &lt;ContentTemplate&gt;
          &lt;div class="NoteList" id="divNoteList" runat="server"&gt;
              &lt;asp:Repeater ID="repNotes" runat="server"&gt;
                  &lt;HeaderTemplate&gt;
                      &lt;table width="98%" cellpadding="3" cellspacing="0"&gt;
                  &lt;/HeaderTemplate&gt;
                  &lt;ItemTemplate&gt;
                      &lt;tr class="repeaterItemRow"&gt;
                          &lt;asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Content/images/DeleteIcon.gif"
                              OnClick="ibRemove_Click" CommandArgument='&lt;%# Container.ItemIndex %&gt;' CommandName='&lt;%# Eval("ID") %&gt;'
                              CausesValidation="false" AlternateText="Delete" /&gt;
                          &lt;%# Eval("Text") %&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/ItemTemplate&gt;
                  &lt;FooterTemplate&gt;
                      &lt;/table&gt;
                  &lt;/FooterTemplate&gt;
              &lt;/asp:Repeater&gt;
              &lt;asp:PlaceHolder ID="phNoNotes" runat="server" Visible="false"&gt;
                  &lt;div class="statusMesssage"&gt;
                      No notes to display.
                  &lt;/div&gt;
              &lt;/asp:PlaceHolder&gt;
          &lt;/div&gt;
      &lt;/ContentTemplate&gt;
  &lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>public partial class NoteListControl : UserControl
  {
      [Ninject.Inject]
      public IUserManager UserManager { get; set; }
  
      protected List&lt;Note&gt; Notes
      {
          get
          {
              if (ViewState["NoteList"] != null)
                  return (List&lt;Note&gt;)ViewState["NoteList"];
              return null;
          }
          set { ViewState["NoteList"] = value; }
      }
  
      public event EventHandler&lt;NoteEventArgs&gt; NoteAdded;
      public event EventHandler&lt;NoteEventArgs&gt; NoteDeleted;
      public event EventHandler&lt;NoteEventArgs&gt; NoteChanged;
  
      protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              UtilityManager.FillPriorityListControl(ddlPriority, false);
          }
      }
  
      protected void ibRemove_Click(object sender, ImageClickEventArgs e)
      {
          System.Diagnostics.Debug.WriteLine("ibRemove POSTBACK"); // This is NEVER hit
      }
  
      public void Fill(List&lt;Note&gt; notes)
      {
          Notes = notes;
          RefreshRepeater();
      }
  
      private void RefreshRepeater()
      {
          if (Notes != null &amp;&amp; Notes.Any())
          {
              var sorted = Notes.OrderByDescending(n =&gt; n.Timestamp);
              Notes = new List&lt;Note&gt;();
              Notes.AddRange(sorted);
              repNotes.Visible = true;
              phNoNotes.Visible = false;
              repNotes.DataSource = Notes;
              repNotes.DataBind();
          }
          else
          {
              repNotes.Visible = false;
              phNoNotes.Visible = true;
          }
      }
  }
  
  public class NoteEventArgs : EventArgs
  {
      public Note Note { get; set; }
      public NoteEventArgs()
      { }
      public NoteEventArgs(Note note)
      {
          this.Note = note;
      }
  }
  </code></pre>
  
  <p>The code is intentionally missing functionality so just disregard that fact.</p>