Reputation: 25
I am using asp.net and vb.net. How can I refer to my web user control instance ServiceForm? Do I need an ID or name somewhere?
Should it be My.Setting.ServiceForm or something like that?
For Each li As ListItem In cblServices.Items
If li.Selected Then
PnlServiceForms.Controls.Add(Page.LoadControl("ServiceForm.ascx"))
'Access this instance of ServiceForm.aspx control - How? - ServiceForm1, ServiceForm2, etc?
End If
Next
Upvotes: 0
Views: 167
Reputation: 219096
Page.LoadControl
returns a reference to the instance of the control. (See MSDN for details.) So you can store that in a variable:
Dim control As ServiceForm = Page.LoadControl("ServiceForm.ascx")
PnlServiceForms.Controls.Add(control)
' Here you can access your instance from the "control" variable
If you need to, you could also make it a class-level variable or whatever other scope is approapriate in your scenario.
Upvotes: 1