How do I Programmically Reference ASP Control

K

kentg

How do I "build" the name of an ASP control in the VB Code behind? I
would like to cycle through several comboboxes using a loop.
(cboReport1, cboReport2, cboReport3, etc.)

ie. in MS-Access I can use the following code to reference a combobox
named cboReport6 and set it's value to 1:

strForm = MyForm
strControlName = "cboReport"
intCount = 6

Forms(strForm).Controls(strControlName & intCount).Value = 1

Thanks.
 
N

~~~ .NET Ed ~~~

Use the FindControl() method of your Page/Control instance. This control
takes a string parameter that represents the ID of the control (the ID you
give like id="cboReport1" runat="server"). You get a base Control object if
it was found. Then you simply has to cast it to the right type (which you
should know which type it is), but ideally you would also verify that the
instance reference you got via FindControls() is of the type you expect.

Emil
 

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

Top