Click here to Skip to main content
15,893,722 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI, A dynamic htmltable with edit image button is built from code behind. the htmltable is in a update panel.Problem is the event handler is not firing, but the page is posting back. any help....
C#
dataCell = new HtmlTableCell();
ImageButton imgEdit = new ImageButton();
imgEdit.ID = "imgButtonEdit" + serialNo;
imgEdit.Click += new ImageClickEventHandler(imgEdit_Click);
ScriptManager.GetCurrent(this).RegisterPostBackControl(imgEdit);
dataCell.Controls.Add(imgEdit);
dataRow.Cells.Add(dataCell);

protected void imgEdit_Click(object sender, ImageClickEventArgs e)
{
//do stuff here
}



There are multiple image buttons in the table
Posted
Updated 14-Oct-13 22:22pm
v3
Comments
Harshil_Raval 15-Oct-13 5:33am    
You can not fire server side click event of dynamically generated control. You have to handle it with jquery/javascript.
[no name] 15-Oct-13 5:51am    
But I have to save data to DB.I can't do it with web method and ajax post calls using jquery

1 solution

Normally if create dynamic control in asp.net this controls are not able to maintain there state on page postback .
for maintaining the state of the dynamic control in asp.net do one think whenever page is getting post recreate those dynamic controls in Page_Init Event
 
Share this answer
 
Comments
[no name] 15-Oct-13 8:38am    
Any other way...?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900