I am just trying to add onClick event to dynamically created ImageButton, and it should be easy, but for some reason, my click event is not firing, no matter what I do.
I created a couple of image buttons and add them to the table.
Here is my code for that bit:
TableCell cell= new TableCell();
ImageButton pic= new ImageButton();
pic.Click += new ImageClickEventHandler(pic_Click);
pic.ImageUrl = "~/Pictures/" + list[j];
pic.Width = 180;
pic.Height = 150;
pic.BorderStyle = BorderStyle.Inset;
pic.BorderColor = Color.DarkRed;
cell.Controls.Add(pic);
row.Cells.Add(cell);
and my method look like this :
public void pic_Click(object sender, ImageClickEventArgs e)
{
//codehere
}
and it just doesn't work, image buttons are created and added to the table as planned, but OnClick is just not doing it's job.. I also tried adding event like this :
pic.Click += pic_Click;
but it's the same. Just to say, I am not doing this in Page_Load method.