0
我創建了一個應用程序,在該應用程序中我已經創建了按鈕的Click事件上的動態控件。但動態創建的控制事件不會在點擊時觸發。 下面是我寫的代碼。在ASP.Net中動態創建控件的事件
ImageButton closeImage = new ImageButton();
closeImage.ID = "ID"+ dr["ID"].ToString();
closeImage.AlternateText = "Delete";
closeImage.ImageUrl = "App_Themes/images/CloseButton.png";
closeImage.Attributes.Add("style", "float:right;cursor:pointer;margin: -19px 1px -10px;");
closeImage.EnableViewState = true;
closeImage.CommandName = "Delete";
closeImage.CommandArgument = dr["ID"].ToString();
closeImage.Attributes.Add("runat", "server");
closeImage.OnClientClick = "return confirm('Are you sure you want to remove this');";
closeImage.Click += new ImageClickEventHandler(this.closeImage_click);
protected void closeImage_click(object sender, ImageClickEventArgs e)
{
ImageButton ibDel = (ImageButton)sender;
}
如果它放在Page_Load()上,它的工作方式相同。是否有任何其他解決方案來解決事件。