troubleshooting Question

Loop through dynamic controls contained by a master page

Avatar of G0ggy
G0ggyFlag for United Kingdom of Great Britain and Northern Ireland asked on
ASP.NETVisual Basic.NET
15 Comments2 Solutions807 ViewsLast Modified:
Hi,

I'm trying to look through some controls which are dynamically created on my webpage, the creating code is this:

For Each row As DataRow In ds.Tables("Questions").Rows
                Dim lbl As Label = New Label()
                lbl.ID = i
                lbl.Style("margin-top") = i
                lbl.Style("margin-left") = "10px"
                lbl.Style("width") = "200px"
                lbl.SkinID = "question"
                lbl.Style("padding-top") = "20px"
                lbl.Style("padding-bottom") = "10px"

                Dim question As String = row("questionText").ToString
                lbl.Text = Convert.ToString(x) & ": " & question
                pnlAssessment.Controls.Add(lbl)

                If row("questiontype") = 37 Then
                    Dim img As Image = New Image()
                    Dim test As String = Server.MapPath("~/secure/images/aqimages/" & row("questionImageFilename").ToString)
                    img.ImageUrl = Server.MapPath("~/secure/images/aqimages/" & row("questionImageFilename").ToString)
                    img.Width = 700
                    img.Height = 300
                    pnlAssessment.Controls.Add(img)
                End If

                Dim childRows As DataRow() = row.GetChildRows(relation)

                For Each childRow As DataRow In childRows
                    Dim rbl As CheckBoxList = New CheckBoxList()

                    rbl.ID = "qid" & row("questionid").ToString
                    rbl.SkinID = "checkboxlist"
                    Dim tPos As Integer = 60 * (i + 1)
                    rbl.Style("margin-top") = i + 20
                    rbl.Style("margin-left") = "50px"
                    rbl.Items.Add(childRow("answerText".ToString))
                    pnlAssessment.Controls.Add(rbl)
                Next
                x = x + 1
            Next

However, if I look through the controls:

For Each ctrl As Control In Form.Controls
            System.Diagnostics.Debug.WriteLine("Control " & ctrl.UniqueID & vbCrLf)
        Next

All I get back is this:

Control ctl00$ctl07

Control ctl00$lblWelcomeMessage

Control ctl00$ctl08

Control ctl00$imgJCBLogo

Control ctl00$ctl09

Control ctl00$mainMenu

Control ctl00$ctl10

Control ctl00$smpMain

Control ctl00$ctl11

Control ctl00$cphNew2ColMain

Control ctl00$ctl12

Control ctl00$cphNew2ColRight

Control ctl00$ctl13

Control ctl00$lblVersionInfo

Control ctl00$ctl14

Control ctl00$lblCopyright

Control ctl00$ctl15

Control ctl00$hplPrivacy

Control ctl00$ctl16

Control ctl00$hplDPA

Control ctl00$ctl17

Control ctl00$lnbRemoveLoginCookies

Control ctl00$ctl18

Control ctl00$cookies

Control ctl00$ctl19

It looks like it is just containing the dynamic control within the master page and not parsing them. How can I get the ID's of these dynamically created controls?
ASKER CERTIFIED SOLUTION
G0ggy

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 15 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 15 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros