I use this method for inserting a textbox in a tablecell
protected void EditAttivitaClick(object sender, EventArgs e) { string attivitaID = ((ImageButton)sender).ID.Split('_')[2]; tableCell =(HtmlTableCell)FindControl("AttivitaDescrizione_" + attivitaID); TextBox txt = new TextBox(); txt.Text = tableCell.InnerHtml; txt.ID = "TxtAttivitaDescrizione_" + attivitaID; tableCell.InnerHtml = ""; } It works correctly. And this function for saving in db the textbox's value:
protected void SalvaAttivitaClick(object sender, EventArgs e) { string attivitaID = ((ImageButton)sender).ID.Split('_')[2]; TextBox txt = (TextBox)FindControl("TxtAttivitaDescrizione_" + attivitaID); string a = txt.Text; attivitaTableAdapter.UpdateID(txt.Text, Int32.Parse(attivitaID)); tableCell.Controls.Clear(); tableCell.InnerHtml = a; } But it doesn't work. beacuse it doesn't find the textbox created previously.
I've put also EnableViewState="true" in the file aspx.
Why?