title: How to loop thru all controls on a web page using VB.net
body: <p>I'm trying to come up with a way to loop thru all the controls ( textboxes, check boxes, dropdown lists,etc) on an aspx page. I tried converting some of the solutions given on line for C# to VB but nothing works.</p>
  <p>I use the</p>
  <pre><code>for all c in me.controls
      id = c.id 
  next 
  </code></pre>
  <p>loop but don't get any of the controls on the page. I have also tried this with the same result:</p>
  <pre class="lang-vb prettyprint-override"><code>Sub checkcontrol(ByRef Parent As Control)
      Dim c As Control
      Dim x As Integer = Parent.Controls.Count
      For Each c In Parent.Controls
          If c.GetType.ToString = &quot;ASP.site_master&quot; Then
              checkcontrol(c)
          ElseIf c.GetType() Is GetType(TextBox) Then
              'is it a Text Box?
              Dim t As TextBox = c
              Debug.Print(&quot;textBox &quot; &amp; c.ID)
          ElseIf c.GetType() Is GetType(DropDownList) Then
              'is it a dropdown list?
              Dim d As DropDownList = c
              Debug.Print(&quot;DropDown Box &quot; &amp; c.ID)
              '   d.ClearSelection()
          ElseIf c.GetType() Is GetType(CheckBox) Then
              Debug.Print(&quot;check Box &quot; &amp; c.ID)
          ElseIf c.GetType() Is GetType(RadioButton) Then
              Debug.Print(&quot;Radio Button &quot; &amp; c.ID)
          End If
      Next
  End sub
  </code></pre>
  <p>The first type I get is &quot;ASP.site_master&quot; since the page is linked to the Site Master.I'm on Visual studio community 2017 and running in the debug mode.</p>
  <p>What am I doing wrong?</p>