title: Dynamic created Buttons VB.Net with Loop
body: <p>I have a very strange Problem with dynamic created Buttons in VB.NET:
  The Click Event is not fired when creating them in a Loop. Here is my code:</p>
  
  <pre><code>    Panel1.Controls.Clear()
      For i As Integer = 0 To 100 Step 1
          Dim b15 As new Button
          b15.Text = "Test3"
          b15.id = "a" &amp; i
          AddHandler b15.Click, AddressOf updateFunc
          Panel1.Controls.Add(b15)
      Next
  </code></pre>
  
  <p>This one doesn't work (only the PageLoad is fired, not the Click Event), but when i type</p>
  
  <pre><code>    Dim b14 As New Button
      b14.Text = "Test"
      b14.id = "asdf"
      AddHandler b14.Click, AddressOf updateFunc
      Panel1.Controls.Add(b14)
  </code></pre>
  
  <p>it works fine and the Event is fired. </p>
  
  <p>The Header of the Function updateFunc is the following:</p>
  
  <pre><code>Protected Sub updateFunc(ByVal sender As Object, ByVal e As System.EventArgs)
  </code></pre>
  
  <p>Any ideas why it doesn't work with the Loop? 
  Thanks for answers!</p>