![](/img/trans.png)
[英]How to implement an if else condition in the code behind for ImageButton OnClick
[英]how to use an ImageButton.OnClick if the ImageButton was created in code behind
我在后面的代码中创建了一个ImageButton。 现在我需要当客户端按下ImageButton时,ImageButton将执行某个功能。 问题是它没有做到这一点。
这是代码 -
var img = new ImageButton();
img.ID = "Del" + i.ToString();
img.ImageUrl = "images/1395958363_meanicons_57.png";
img.Width = 48;
img.Height = 38;
img.Click += new System.Web.UI.ImageClickEventHandler(this.btnForDelete_Click); //doesn't work!!
Lab.Controls.Add(img); //put the image in a label
声明要在onClick事件上触发的回调:
public void DynamicClick(object sender, EventArgs e) {
// do something
}
将其添加到Click
EventHandler
列表:
img.Click += new EventHandler(DynamicClick);
EventHandler不能与LinkButton一起使用。 试试以下内容:
img.Click += new ImageClickEventHandler(onImageClick);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.