Biswarup Saha

Biswarup Saha

  • NA
  • 58
  • 31.2k

Dynamically created image button click event is not fired

Apr 9 2014 3:08 AM
On grid RowDataBound based on some condition i've added imagebutton dynamically. parallelly i want to add event for this button click. here is my code snippet
 
protected void GV3_RowDataBound(object sender, GridViewRowEventArgs e)     
if (e.Row.RowType == DataControlRowType.DataRow)             
{                 
TableCell cell = new TableCell();                 
ImageButton bttn = new ImageButton();                 
bttn.CommandName = "Delete";                 
bttn.ImageUrl = "delete.png";                 
bttn.ToolTip = "Click to delete this record";                 
bttn.CommandArgument = e.Row.Cells[0].Text;                 
cell.Controls.Add(bttn);                 
e.Row.Cells.Add(cell);                 
bttn.OnClientClick = "return confirm('Are you sure you to delete " + e.Row.Cells[0].Text + "?');"
}
 That message popup box comes, but i'm unable to catch that click event. while click on a row i want to delete that row, so want to create event dynamically. for that i've used this following dynamic click event
 
bttn.Click += new ImageClickEventHandler(b_Click);   
private void b_Click(object sender, EventArgs e)     
{ //delete record 
}
 but this above code also not working. Please help me to solve this. Thanks in advance.