Reference controls by name

Tags:
VB.NET
I need to point to a control whose name I won't know until run-time. How do I do it? My code currently looks a little like this: ======== Dim ctlControl as Control Dim strName as String ctlControl = cType(strName, Control) ...now do stuff with/to the control named strname... ======== Now this is clearly rubbish, but it illustrates what I want to do. Any ideas?

Answer Wiki

Thanks. We'll let you know when a new response is added.

Look into FindControl() as a method to use from the container that the dynamic control is in using the ID of the created control, hopefully strName is the ID …

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • VbExcel
    Sorry to reply so late! Try: .Controls.Add Type:='type of control', temporary:='Boolean' With .Controls.Count 'new controls always at end of list .Caption = "Something useful to you." .OnAction = "Some Procedure name" .Tag = "Some identifier useful to you." End With
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following