My code generates an TextBox on the fly in C# (page_load function). Can I access it in the code later? It does give me compilation error and does not seem to work. Can someone verify ?
Code for additonal problem
aContent += "<table>";
aContent += "<tr><td>lablel </td><td style='bla blah'><input type='textbox' id='col-1' name='col-1'/></td></tr> ... 10 such rows here
</table>"
spanMap.InnerHtml = aContent;
The contents are rendered OK but recusrive iteration does not return the textbox. I am calling it like this
TextBox txt = (TextBox)this.FindControlRecursive(spanMap, "col-1");
// txt = (TextBox) spanMapping.FindControl("col-1"); this does not work too
if (txt != null)
{
txt.Text = "A";
}
Assuming that you’re persisting it correctly, you should be able to access it in code-behind using the
FindControlmethod. Depending on where the control is, you may have to search recursively through the control hierarchy:Using
FindControlRecursive:If you still can’t find it using the above method, make sure that you’re creating the control during after every postback, somwhere before
Page_Load, likeOnInit.EDIT
I think you need to change the way you’re adding content to the container. Instead of using a
<span>, I would use aPanel, and instead of building markup, simply add controls to the panel in code-behind: