catch click event from runtime created imagebutton on webform

On a webform I am creating an array of imagebuttons that holds different images collected from a directory. How can I catch the click event from one of these imagebuttons and store the name of the image before returning?

Below is the code to create them. Ideas/CodeSnippets on how to register event and catch the buttonclick would be appreciated !
Dim Currentfile As String
Dim xx As String
Dim Ff() As String
Dim i As String
iPanel = -1
 
For Each Currentfile In Directory.GetFiles(Session("imageDir")+ "images\")
            Ff = Split(Currentfile, "\")
            Currentfile = Ff(Ff.Length - 1)
            xx = Mid(Currentfile, Currentfile.Length - 3, 4)
            If xx = ".jpg" Or xx = ".gif" Then
 
                iPanel = iPanel + 1
 
                Pics(iPanel) = New ImageButton
                Pics(iPanel).ImageUrl = "images\" + Currentfile
                Pics(iPanel).AlternateText = Currentfile
 
                PicturePanel.Controls.Add(Pics(iPanel))
       End If

Open in new window

dmveAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill-HansonCommented:
You just need to define a click handler function, then set the OnClick member of the ImageButton.  I'm not sure how to get the name of the control that was clicked, though.
' The event handler.
Sub ImageButton_Click(sender As Object, e As ImageClickEventArgs) 
	Label1.Text = "You clicked the ImageButton control at the coordinates: (" & _ 
		e.X.ToString() & ", " & e.Y.ToString() & ")"
End Sub
 
' In your code...
If xx = ".jpg" Or xx = ".gif" Then
 
	iPanel = iPanel + 1
	Pics(iPanel) = New ImageButton
	Pics(iPanel).ImageUrl = "images\" + Currentfile
	Pics(iPanel).AlternateText = Currentfile
	Pics(iPanel).OnClick = ImageButton_Click
	PicturePanel.Controls.Add(Pics(iPanel))
	
End If

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dmveAuthor Commented:
Sorry for the late respons. Thanks for tip. Did not fully solve the question. I Only have the OnClientClick event. And when trying to use it, it complaints over this line "Pics(iPanel).OnClick = ImageButton_Click" that is says MUST BE "Pics(iPanel).OnClick = ImageButton_Click()"

I will play a little more with it and come back later on this issue... So I'll keep it on hold for another few days...
0
dmveAuthor Commented:
Thanks ;-) Got it working now.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.