Creating an Event Handler for dymanically generated controls

  • Thread starter Thread starter Steve Caliendo
  • Start date Start date
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
 
after the control has been generated in the code do

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

hth
-ashish
 
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
 
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
 
Back
Top