A
Alain
Hello,
I am trying to dynamically add many instances of a user control inside
a placeholder.
The user control exposes an event raised when a button is pushed.
How can I handle such event for every user control in the placeholder?
Using the code below, the event is fired only when you press the
button of the last user control added in the placeholder.
Thanks
Alain
Public WithEvents ticket As test_control
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim i As Integer
Dim tbl As New HtmlTable
For i = 1 To 10
Dim row As New HtmlTableRow
Dim cell As New HtmlTableCell
testc = New test_control
testc = DirectCast(LoadControl("test-control.ascx"),
test_control)
testc.Content = "User Control number " & i
testc.EditMode = True
testc.TicketId = i
cell.Controls.Add(ticket)
row.Cells.Add(cell)
tbl.Rows.Add(row)
Next
PlaceHolder1.Controls.Add(tbl)
End Sub ' Page Load
Private Sub testc_Click(ByVal sender As Object, ByVal e As
EventArgs) Handles testc.Event1
'Event stuff needs to be done here
'but event happens only for last control added
End Sub ' testc_Click
I am trying to dynamically add many instances of a user control inside
a placeholder.
The user control exposes an event raised when a button is pushed.
How can I handle such event for every user control in the placeholder?
Using the code below, the event is fired only when you press the
button of the last user control added in the placeholder.
Thanks
Alain
Public WithEvents ticket As test_control
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim i As Integer
Dim tbl As New HtmlTable
For i = 1 To 10
Dim row As New HtmlTableRow
Dim cell As New HtmlTableCell
testc = New test_control
testc = DirectCast(LoadControl("test-control.ascx"),
test_control)
testc.Content = "User Control number " & i
testc.EditMode = True
testc.TicketId = i
cell.Controls.Add(ticket)
row.Cells.Add(cell)
tbl.Rows.Add(row)
Next
PlaceHolder1.Controls.Add(tbl)
End Sub ' Page Load
Private Sub testc_Click(ByVal sender As Object, ByVal e As
EventArgs) Handles testc.Event1
'Event stuff needs to be done here
'but event happens only for last control added
End Sub ' testc_Click