Hello. I have been developing on this project for the last month and this particular function is used MANY MANY times throughout the project and I have had 0 problems with it to date. I added a new panel and all of a sudden some of my core feautres started throwing Null Exceptions or even Overflowing a dll (apparently from infinate loops?) I do not see how this is even relevent and nothing has changed in the code that is no longer working.... please advise

Public Function GetControlById(ByVal ParentCntrl As Control, ByVal TargetCntrl As String) As Control
            Try
                Dim ctl As Control = ParentCntrl
                Dim ctls As New LinkedList(Of Control)
                While Not ctl.Equals(Nothing)
                    If ctl.ID = TargetCntrl Then
                        Return ctl
                    End If
                    For Each child As Control In ctl.Controls
                        If child.ID = TargetCntrl Then
                            Return child
                        End If
                        If child.HasControls Then
                            ctls.AddLast(child)
                        End If

                    Next
                    If Not ctls.First.Value.ClientID = Nothing Then
                        ctl = ctls.First.Value
                        ctls.Remove(ctl)
                    End If

                End While
                Return Nothing
            Catch ex As Exception

            End Try

This is the function I am using to find a control.

Dim ID As String = CType(invf.GetControlById(pnlComputerDetailsView, "lblComputerIdDetail"), Label).Text

            Dim AssignedTo As String = CType(invf.GetControlById(pnlComputerDetailsView, "lblComputerAssignmentDetail"), Label).Text

The first line works fine...the second line will throw a null exeption. I do not know why. The lblComputerAssignmentDetail is created and populated at the time this is called. >< CODE HEADACHE. Please advise

Ehm... Case sensitive ID's... :S


*drinks more cofee*

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.