以编程方式更改ImageUrl onclick ImageButton C#

时间:2016-08-24 13:52:14

标签: c# asp.net

我试图更改ImageUrl onclick我的Repeater上的Imagebutton。我必须从代​​码(cs文件)后面更改它,而不是使用jquery或js。

<asp:ImageButton ID="imgLike" ImageUrl="Content/images/thumbsup.png" onclick="imgLike_Click" runat="server" style="width:25px;height:25px" />

这是代码

  protected void imgLike_Click(object sender, ImageClickEventArgs e)
    {
        ImageButton imgLike = (ImageButton)rptinserting.FindControl("imgLike");
        imgLike.ImageUrl = "Content/images/thumbsup1.png";
    }

1 个答案:

答案 0 :(得分:0)

您将发件人转发回ImageButton并更改ImageUrl

protected void imgLike_Click(object sender, ImageClickEventArgs e)
{
    ImageButton imgLike = sender as ImageButton;
    imgLike.ImageUrl = "/Content/images/thumbsup1.png";
}