You'll need to use
AddHandler[
^] to attach the event handler.
You should also move the code that creates the controls from the
Load
event to the
Init
event. This will ensure that they're created early enough in the page lifecycle to handle post-back events.
And there's no point creating an array of the controls that you're adding as a local variable, since you never use that array anywhere.
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Dim intRijen, intKolommen As Int16
intRijen = 4
intKolommen = 3
For nR = 0 To intRijen
For nK = 0 To intKolommen
Dim imgbPrent As New ImageButton
imgbPrent.ID = CStr(nR) & CStr(nK)
imgbPrent.Width = 100
imgbPrent.Height = 100
imgbPrent.ImageUrl = "~/prentjes/" & CStr(nR) & CStr(nK) & ".jpg"
Panel1.Controls.Add(imgbPrent)
AddHandler imgbPrent.Click, AddressOf imgbPrent_Click
Next
Panel1.Controls.Add(New LiteralControl("<br />"))
Next
End Sub
Protected Sub imgbPrent_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
Dim btn As ImageButton = DirectCast(sender, ImageButton)
btn.ImageUrl = "~/prentjes99.jpg"
End Sub