
Creating references to Controls ID's/Names in code behind pages
Hi Robert. Try putting your controls into an array, and then referencing
the array elements, like this:
Dim ImgBtn() as New ImageButton = {btnVal1, btnVal2, btnVal3, ... btnVal15}
Dim ii as Integer
For ii = 0 to How Many Controls should show a tick
ImgBtn(ii).ImageUrl = "images/ticked.jpg"
Next
I don't know of a way to "programatically" build a control's name. And
unfortunately, VB.NET doesn't support Control Arrays like VB 6 does. So,
what I illustrated above is as close as you can get.
Hope that helps!
Regards,
Jeff Ptak
Quote:
> Hi All,
> Here is what I am trying to do:
> I have an ASPX project that has a lot of repeatition in the code. A
> lot of this code that is repeated because at the moment I haven't
> found a way to programmatically create a "control's" ID and assign it
> a value.
> The controls in question have been labelled btnVal1, btnVal2, btnVal3,
> ...btnVal15. They are all ImageButtons
> Now, not all the controls are shown at one time, and what I want to do
> is something like (very simplified)
> for i = 1 to how many controls should show a tick
> temp = "btnVal" & CStr(i)
> temp.imageurl = "images/ticked.jpg"
> Next
> Of course, I get the error that imageurl is not in the class String.
> I have tried the CTyping the string to an imagecontrol but I get an
> error stating the String cannot be converted to a type control.
> Can anyone suggest ways of begin able to do this..
> Thanks,
> Robert