Creating an Event Handler for dymanically generated controls

S

Steve Caliendo

Hi,

My last post was not worded correctly. What I really need to know is how
(what to type) to create an event handler for some ImageButtons that I
generate at run-time. I tried this:

Private Sub ImageButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)

Stop

End Sub



But the stop statement was not encountered after clicking on the
ImageButtons.



Thanks for any help,



Steve
 
A

ashish

after the control has been generated in the code do

AddHandler CType(Page.FindControl("MyGeneratedControl"),
ImageButton).Click, ImageButton_Click

hth
-ashish
 
R

Raterus

Is this what you are after?

Private Sub ImageButton_Command(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs)
'do something
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim btn As ImageButton = new ImageButton
AddHandler btn.Command, AddressOf ImageButton_Command

End Sub

--Michael
 
S

Steve Caliendo

Yes, Thanks All !

Steve

Is this what you are after?

Private Sub ImageButton_Command(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.CommandEventArgs)
'do something
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim btn As ImageButton = new ImageButton
AddHandler btn.Command, AddressOf ImageButton_Command

End Sub

--Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top