![](/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.