I'm getting object errors when I try to FindControl on a dynamically created textbox. The textbox is added to a placeholder, which resides on a datagrid, which in turn resides on a repeater.
When I test this, I get errors on the line "ThisResponse = thisTB.Text.Trim();". I've also tried accessing the textbox as a child of the placeholder, but that doesn't seem to help either. Any ideas?
thanks!
tigerjade
"Always code as if the person who ends up maintaining your code will be a violent psychopath who knows where you live." -- Martin Golding
Code:
foreach (RepeaterItem rItem in QuestionRepeater.Items)
{
DataGrid RADG = rItem.FindControl("AnswerDG") as DataGrid;
foreach (DataGridItem dgItem in RADG.Items)
{
if (dgItem.ItemType == ListItemType.Item || dgItem.ItemType == ListItemType.AlternatingItem)
{
Label QIDLbl = dgItem.FindControl("DGQuestionIDLbl") as Label;
Label AnsIDLbl = dgItem.FindControl("AnswerIDLbl") as Label;
Label GNLbl = dgItem.FindControl("GroupNameLbl") as Label;
string SubQID = QIDLbl.Text;
string SubAID = AnsIDLbl.Text;
string SubGroupName = GNLbl.Text;
string ThisAnswer = String.Empty;
string ThisResponse = String.Empty;
string TBName = "AnswerTB" + SubQID.ToString() + SubAID.ToString();
TextBox thisTB = dgItem.FindControl(TBName) as TextBox;
ThisResponse = thisTB.Text.Trim();
When I test this, I get errors on the line "ThisResponse = thisTB.Text.Trim();". I've also tried accessing the textbox as a child of the placeholder, but that doesn't seem to help either. Any ideas?
thanks!
tigerjade
"Always code as if the person who ends up maintaining your code will be a violent psychopath who knows where you live." -- Martin Golding