title: ASP.NET How to do For Loop with Controls
body: <p>For Each Control In Page.Header.Controls</p>
  
  <p>How can I do something as above, at the moment getting the error 
  "Control is a Type and Cannot be used as an expression"</p>
  
  <p>The Complete Code is as follows</p>
  
  <pre><code>Try
          ' I only do this on my production servers, so I declare those here.'
          If Request.ServerVariables("server_name") = "www.myproductionurl.com" Then
              ' Allow scripts and css to logged in CMS users'
  
              Dim checkLogin As New Controls.Login
              If checkLogin.IsLoggedIn &lt;&gt; True Then
                  For Each Control In Page.Header.Controls
                      If Control.GetType.Name = "EktronJsControl" Or Control.GetType.Name = "EktronCssControl" Or Control.GetType.Name = "EktronModalCss" Then
                          Page.Header.Controls.Remove(Control)
                      Else
                          ' Removes the extra bubble inline style stuff that wasn't put in a CSS.''
                          Dim litControl As LiteralControl = Control
                          If litControl.Text = Nothing Then
                              litControl.Text = ""
                          End If
  
                          ' Removing blank.css file'
                          Dim htmlLink As HtmlLink = Control
                          If htmlLink.Href = "/css/blank.css" Then
                              Page.Header.Controls.Remove(Control)
                          End If
                      End If
                  Next
              End If
          End If
      Catch ex As Exception
  
      End Try`
  </code></pre>