I have an ImageButton inside a repeater control. I have attached an eventhandler to the OnClick event of the ImageButton. But when I click the ImageButton the event does not
Inside a repeater control, a button does not behave the same way as out.
You need to set the "CommandName" property of the button and in the Repeater.ItemCommand event check for that command name and do your logic there.
I had det same problem, and solved it by using av asp:Linkbutton with a with the "OnCommand" event. My markup and code behind is posted below.
Markup:
<asp:Repeater ID="rptRecipients" runat="server">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="LabelRecipient" Text='<%# Eval("Value")%>' runat="server"></asp:Label>
</td>
<td>
<asp:LinkButton OnCommand="lbRemove_Command" CommandArgument='<%# Eval("Key")%>'
CommandName="Remove" runat="server">
<asp:Image ImageUrl="~/Images/delete.png" runat="server" />
</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Code behind:
protected void lbRemove_Command(object sender, CommandEventArgs e)
{
switch (e.CommandName)
{
case "Remove":
Recipients.Remove(e.CommandArgument.ToString());
rptRecipients.DataSource = Recipients;
rptRecipients.DataBind();
break;
}
}