I am trying to add a unique name to each textbox that I'm adding to a table.
I've tried:
TableRow someRow = new TableRow();
TableCell someCell = new TableCell();
TextBox someTextbox = new TextBox();
someTextbox.Attributes.Remove("name");
someTextbox.Attributes.Add("name",itsId);
someCell.Controls.Add(someTextBox);
someRow.Cells.Add(someCell);
theTable.Rows.Add(someRow);
The html generated includes both my name and the autogenerated name as attributes of the textbox.
Unfortunately, when I run a FindControl
, by my name, I get a null reference, even though it still works to find it by the autogenerated name.
What do I need to do to find the control by my name? When / why is it autogenerating names for my controls?
Successful code:
TextBox tb = (TextBox)FindControl(autogeneratedID); WriteToSomeOtherDiv(tb.Text);
Unsuccessful code:
TextBox tb = (TextBox)FindControl(myId); WriteToSomeOtherDiv(tb.Text);