Does anyone know if it is possible to create a global event handler(s) for dynamic controls???
If not, is there a work around?
Printable View
Does anyone know if it is possible to create a global event handler(s) for dynamic controls???
If not, is there a work around?
I don't understand what you mean by a "global" event handler.
:wave:
I assume you mean one eventhandler that all of the dynamically generated controls can use?
If you want to add an eventhandler to like an array of controls that you dynamically add to the page, here is one way to do this:
Have Fun!Code:Protected WithEvents btn As System.Web.UI.WebControls.Button
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim i As Integer
For i = 0 To 3
btn = New System.Web.UI.WebControls.Button
btn.Text = "blabla"
btn.ID = i
AddHandler btn.Click, AddressOf btn_Click
Me.Controls.Add(btn)
Next
btn = Nothing
End Sub
Private Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Label1.Text = sender.id
End Sub