<p>Here's the code from the ascx that has the repeater:</p>

<pre><code>&lt;asp:Repeater ID="ListOfEmails" runat="server" &gt;
    &lt;HeaderTemplate&gt;&lt;h3&gt;A sub-header:&lt;/h3&gt;&lt;/HeaderTemplate&gt;
    &lt;ItemTemplate&gt;
        [Some other stuff is here]
        &lt;asp:Button ID="removeEmail" runat="server" Text="X" ToolTip="remove" /&gt;
    &lt;/ItemTemplate&gt;
&lt;/asp:Repeater&gt;
</code></pre>

<p>And in the codebehind for the repeater's databound and events:</p>

<pre><code>Protected Sub ListOfEmails_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles ListOfEmails.ItemDataBound
    If (e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem) Then
        Dim removeEmail As Button = CType(e.Item.FindControl("removeEmail"), Button)
        removeEmail.CommandArgument = e.Item.ItemIndex.ToString()

        AddHandler removeEmail.Click, AddressOf removeEmail_Click
        AddHandler removeEmail.Command, AddressOf removeEmail_Command
    End If
End Sub

Sub removeEmail_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Response.Write("&lt;h1&gt;click&lt;/h1&gt;")
End Sub

Sub removeEmail_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
    Response.Write("&lt;h1&gt;command&lt;/h1&gt;")
End Sub
</code></pre>

<p>Neither the click or command is getting called, what am I doing wrong?</p>

[{'answer_id': 42404, 'author': 'Brad Wilson', 'author_id': 1554, 'author_profile': 'https://Stackoverflow.com/users/1554', 'pm_score': 0, 'selected': False, 'text': "<p>Here's an experiment for you to try:</p>\n\n<p>Set a breakpoint on ListOfEmails_ItemDataBound and see if it's being called for postbacks.</p>\n"}, {'answer_id': 42412, 'author': 'FlySwat', 'author_id': 1965, 'author_profile': 'https://Stackoverflow.com/users/1965', 'pm_score': 5, 'selected': True, 'text': '<p>Controls nested inside of Repeaters do not intercept events. Instead you need to bind to the <code>Repeater.ItemCommand</code> Event.</p>\n\n<p><a href="https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.repeater.itemcommand" rel="nofollow noreferrer"><code>ItemCommand</code></a> contains <a href="https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.repeatercommandeventargs" rel="nofollow noreferrer"><code>RepeaterCommandEventArgs</code></a> which has two important fields:</p>\n\n<ul>\n<li>CommandName</li>\n<li>CommandArgument</li>\n</ul>\n\n<p>So, a trivial example:  </p>\n\n<pre class="lang-cs prettyprint-override"><code>void rptr_ItemDataBound(object sender, RepeaterItemEventArgs e)\n{\n    if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)\n    {\n        // Stuff to databind\n        Button myButton = (Button)e.Item.FindControl("myButton");\n\n        myButton.CommandName = "Add";\n        myButton.CommandArgument = "Some Identifying Argument";\n    }\n}\n\nvoid rptr_ItemCommand(object source, RepeaterCommandEventArgs e)\n{\n    if (e.CommandName == "Add")\n    {\n        // Do your event\n    }\n}\n</code></pre>\n'}, {'answer_id': 42427, 'author': 'Craig', 'author_id': 2047, 'author_profile': 'https://Stackoverflow.com/users/2047', 'pm_score': 2, 'selected': False, 'text': '<p>You need to handle the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemcommand.aspx" rel="nofollow noreferrer">ItemCommand event</a> on your Repeater. Here\'s <a href="http://www.developer.com/net/asp/article.php/3609466" rel="nofollow noreferrer">an example</a>.</p>\n\n<p>Then, your button clicks will be handled by the ListOfEmails_ItemCommand method. I don\'t think wiring up the Click or Command event (of the button) in ItemDataBound will work.</p>\n'}, {'answer_id': 4220093, 'author': 'catfood', 'author_id': 12802, 'author_profile': 'https://Stackoverflow.com/users/12802', 'pm_score': 0, 'selected': False, 'text': "<p>You know what's frustrating about this?</p>\n\n<p>If you specify an OnClick in that asp:Button tag, the build <em>will</em> verify that the named method exists in the codebehind class, and report an error if it doesn't... even though that method will never get called.</p>\n"}, {'answer_id': 4996126, 'author': 'Piotr Latusek', 'author_id': 562786, 'author_profile': 'https://Stackoverflow.com/users/562786', 'pm_score': 2, 'selected': False, 'text': "<p>If you're planning to use ItemCommand event, make sure you register to ItemCommand event in Page_Init not in Page_Load.</p>\n\n<pre><code>protected void Page_Init(object sender, EventArgs e)\n{\n    // rptr is your repeater's name\n    rptr.ItemCommand += new RepeaterCommandEventHandler(rptr_ItemCommand);\n}\n</code></pre>\n\n<p>I am not sure why it wasn't working for me with this event registered in Page_Load but moving it to Page_Init helped.</p>\n"}]
['https://Stackoverflow.com/questions/42396', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1414/']