Events for Dynamic Controls

PROKA

Junior Contributor
Joined
Sep 3, 2003
Messages
249
Location
Bucharest
I have created a control named "control.ascx", and I am dynamically generating objects : Dim ctrl As control = CType(LoadControl("control.ascx"), control)

I don't know how to handle events for this controls

I know it has something to do with AddHandler and 'delegates' but I have no ideea of how to implement those

See attached code
 
Last edited:
PROKA said:
The problem is, you are only drawing the controls on the first load. . . change your Page_Load to:
Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
	Handles MyBase.Load
 For i As Integer = 1 To 5
  Dim ctrl As control = CType(LoadControl("control.ascx"), control)
  ctrl.SomeVariable = i
  Panel1.Controls.Add(ctrl)
 Next
End Sub
it should work as expected. . .

But then again, ASPX is not my strength.
 
Back
Top