c#/ asp.net/ .net/ visual-studio

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;

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;
    }
}

暂无
暂无

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question Repeater in ASP.net ASP.NET Bind binary image to image control in repeater Trying to use controls in my repeater control (asp.net) Trying to access buttons inside of a asp.net repeater ASP.NET: Repeater with Button inside GridView: Call OnRowCommand of the GridView Asp.Net Button click Event inside Repeater inside UpdatePanel asp.net invalid postback for button onclick inside repeater footer c# asp.net repeater - create button based on condition ASP.NET Repeater - how to refresh data on button submit Asp.Net Button In Repeater not triggering any action
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM