1

I have a problem using imageButton in a Repeater.I tried alot of method and didnt fix the problem.I used the repeater item command still not working.when i click on the imageButton nothing happen.

<asp:ImageButton ID="ImageButton1" runat="server" Height="200px" Width="150px" ImageUrl='<%#"~/imageHandler.ashx?Mid=" + DataBinder.Eval(Container.DataItem, "Mid")%>' CommandName="img" CommandArgument='<%#Eval("Mid") %>' />

  protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        ModalPopupExtender mpe = (ModalPopupExtender)e.Item.FindControl("mpe");
        LinkButton Lbtn = (LinkButton)e.Item.FindControl("LinkButton1");
       switch (e.CommandName)
        {
            case "btn1":

                Session["id"] = Lbtn.CommandArgument.ToString();

                mpe.Show();

                break;
            case "img":
                Response.Write("event is fired");
                break;

            default:
                break;
VDWWD
  • 35,079
  • 22
  • 62
  • 79
SaSh
  • 13
  • 3
  • Seems to be duplicate. See http://stackoverflow.com/questions/1940206/imagebutton-in-asp-net-repeater-does-not-fire-onclick-eventhandler – Alfishe Dec 26 '16 at 02:16
  • i dont want to use a linkbutton i just want to handle the event when i click on the imageButton.And I used repeater item command and set a command name for imagebutton without using onclick. – SaSh Dec 26 '16 at 02:28

1 Answers1

3

Take a look at the snippet below. Your LinkButton code seems to be correct, but did you add the OnItemCommand to the Repeater?

<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
    <ItemTemplate>
        <asp:ImageButton ID="ImageButton1" runat="server" CommandName="img" CommandArgument='<%#Eval("Mid") %>' />
    </ItemTemplate>
</asp:Repeater>

Code behind

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    string commandArgument = e.CommandArgument.ToString();

    if (e.CommandName == "img")
    {
        Response.Write("event is fired: " + commandArgument);
    }
    else if (e.CommandName == "btn1")
    {
        Session["id"] = commandArgument;
    }
}
VDWWD
  • 35,079
  • 22
  • 62
  • 79
  • yes I have the onItemCommand in the repeater and avery thing is working well and btn1 is working except the image button not doing anything and here is my imagebutton ' ' – SaSh Dec 26 '16 at 14:12
  • Test my snippet. If it works (and it does) expand from there. – VDWWD Dec 26 '16 at 15:30