So my discovery today is an example of silly programming errors that I tend to supprise me.
Some of my controls in ASP.net don’t have assigned ID’s. However using the code below you should see an example of one control returning the first IsNothing line without a value, but once ClientID is used it will populate the control’s ID so it will be found the second time. I recommend just using ClientID for logic, if the ID is not populated it will autogenerate it for you to be handled on your code proceeding after.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
EnumerateControls(Me.Controls, 0) Private Function EnumerateControls(MyControlCollection As ControlCollection, index As Integer) index += 1 For Each MyControl As Control In MyControlCollection For index = 0 To index 'Debug.Write(vbTab) Next If Not IsNothing(MyControl.ID) Then 'If MyControl.ID.Length > 0 Then If MyControl.ID = "TableRow2" Then End If Debug.WriteLine(MyControl.GetType().ToString & ": " & MyControl.ID & " - " & MyControl.Parent.ID) If MyControl.HasControls Then EnumerateControls(MyControl.Controls, index) End If 'End If Else If IsNothing(MyControl.ID) Then Debug.WriteLine("Nothing - " & MyControl.ID) End If If IsNothing(MyControl.ID) Then Debug.WriteLine("Nothing2 - " & MyControl.ClientID & MyControl.ID) End If Debug.WriteLine(MyControl.ID) If MyControl.ClientID = "ctl46" Then Debug.WriteLine(MyControl.GetType()) If IsNothing(MyControl.ID) Then Debug.WriteLine("Nothing - " & MyControl.ClientID & MyControl.ID) End If End If Debug.WriteLine(MyControl.ClientID) End If Next End Function |