[thelist] (asp.net) accessing controls created at runtime.

Tab Alleman talleman at Lumpsum.com
Tue Feb 21 10:25:42 CST 2006

I am creating controls at runtime, and they show up on the page, but when the page is submitted, I can't find them.  What am I doing wrong?

To reduce the code to critical elements, I have a datacell on my .aspx page like this:

<td class='TableData' id="tdAttorney" runat="server" nowrap></td>

Then in my vb.net code-behind, I populate the cell like this:

Dim  tdAttorney As System.Web.UI.HtmlControls.HtmlTableCell
tdAttorney = e.Item.FindControl("tdAttorney")

'add textboxes
Dim tbAttorneyFirstName As New System.Web.UI.HtmlControls.HtmlInputText
Dim tbAttorneyLastName As New System.Web.UI.HtmlControls.HtmlInputText
            With tbAttorneyFirstName
                .Value = e.Item.DataItem("AttorneyFirstName").ToString
                .Size = 20
                .ID = "tbAttorneyFirstName"
                .MaxLength = 50
            End With
            With tbAttorneyLastName
                .Value = e.Item.DataItem("AttorneyLastName").ToString
                .Size = 20
                .ID = "tbAttorneyLastName"
                .MaxLength = 50
            End With

            With tdAttorney
            End With


Ok, all of this works...the textboxes show up on the page.  In the submit_click handler, I've got this:

                tdAttorney = itemSI.FindControl("tdAttorney")

                tbAttorneyFirstName = tdAttorney.FindControl("tbAttorneyFirstName")
                tbAttorneyLastName = tdAttorney.FindControl("tbAttorneyLastName")

----when I stop the page in the debugger, it's finding tdAttorney (the datacell), but it's saying it doesn't contain any controls.  The page doesn't contain the controls, either.  

What am I missing?

More information about the thelist mailing list