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:
Panel1.Controls.Clear()
For i As Integer = 0 To 100 Step 1
Dim b15 As new Button
b15.Text = "Test3"
b15.id = "a" & i
AddHandler b15.Click, AddressOf updateFunc
Panel1.Controls.Add(b15)
Next
This one doesn't work (only the PageLoad is fired, not the Click Event), but when i type
Dim b14 As New Button
b14.Text = "Test"
b14.id = "asdf"
AddHandler b14.Click, AddressOf updateFunc
Panel1.Controls.Add(b14)
it works fine and the Event is fired.
The Header of the Function updateFunc is the following:
Protected Sub updateFunc(ByVal sender As Object, ByVal e As System.EventArgs)
Any ideas why it doesn't work with the Loop? Thanks for answers!