Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Web Controls at runtime

Status
Not open for further replies.

Deleco

Programmer
Feb 25, 2002
109
GB
Hi all,

I am having a bit of a nightmare i am creating controls at runtime in a panel, in another panel and then inside a table. The only way i can figure out how to access these dynamically created controls is with this massive loop/if structure. Does anyone know of an easier method.

Code:
For Each ctrl In pnlParent.Controls
            If ctrl.GetType.FullName = "System.Web.UI.WebControls.Panel" Then
                For Each ctrl2 In ctrl.Controls
                    If ctrl2.GetType.FullName = "System.Web.UI.WebControls.Table" Then
                        tbl = ctrl2
                        For Each ctrl3 In tbl.Rows
                            If ctrl3.Cells(1).Controls.Count > 0 Then
                                chk = ctrl3.Cells(1).Controls(0)
                                If chk.Checked = True Then
                                    Dim dr As DataRow
                                    Dim sSplit() As String
 
                                    sSplit = Split(chk.ID, "^")

 
                                    dr.Item("PROLE_ID") = sSplit(0).ToString

                                    dr.Item("COURSE_ID") = sSplit(1).ToString

                                    dr.Item("DELEGATE_NAME") = sSplit(2).ToString

 
                                    dt.Rows.Add(dr)

                                    dt.AcceptChanges()
                                End If
                            End If
                        Next
                    End If
                Next
            End If

       Next

Many thanks in advance for any assistance

Deleco
 
Look at Control.FindControl Method

Overload List
Searches the current naming container for a server control with the specified id parameter.

Overloads Public Overridable Function FindControl(String) As Control


- free online Compare/Diff of snippets
 
The only control that isn't actually created at run time is the pnlParent at the very top. I create more panels inside that and then tables inside the created panels, and finally a checkbox inside the cell of the table. How using FindControl can i gain access to the dynamically created checkbox.



Deleco
 
Any more suggestions anyone.... :)

Deleco
 
You might get better results in the ASP.NET forum (forum855) for this.

As JohnYingling said, if you know the name of each control the FindControl method would be a good bet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top