0

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.