title: Detecting if controls exist in a control collection
body: <p><strong><em>UPDATE:</strong> Apologies on lack of clarity I realise I could iterate over the controls collection, was just looking for a better/more efficient method.</em></p>
  
  <p>I am trying to dynamically add some css and js elements into an ASP.Net page at runtime, but because this code is used in mutliple controls I need to ensure that the relevant links are only injected once.</p>
  
  <p>Currently I have the folowing code in the OnPreRender event.</p>
  
  <pre><code>Dim head As HtmlControls.HtmlHead = Me.Parent.Page.Header
  
  If Not _useCustomStyles Then
  
      Dim litCustomCss As New LiteralControl("&lt;link rel=" &amp; Chr(34) &amp; "stylesheet" &amp; Chr(34) &amp; " href=" &amp; Chr(34) &amp; "/css/udPart_core.css" &amp; Chr(34) &amp; " type=" &amp; Chr(34) &amp; "text/css" &amp; Chr(34) &amp; " media=" &amp; Chr(34) &amp; "screen" &amp; Chr(34) &amp; " /&gt;" &amp; vbCrLf)
  
      litCustomCss.ID = "cssCustom"
  
      If Not head.Controls.Contains(litCustomCss) Then
          head.Controls.Add(litCustomCss)
      End If
  
  End If
  </code></pre>
  
  <p>Does .Contains look for this instance of an object (which I assume is why this is failing)?  </p>
  
  <p>Is there a way to check the controls collection for a specific id?  Or am I going to have to write a sub to loop through the existing controls in the collection checking for the id.</p>
  
  <p>Thanks</p>