User Controls Events

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
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top