Reputation: 13
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;
Upvotes: 1
Views: 1916
Reputation: 35544
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;
}
}
Upvotes: 3