views:

121

answers:

2

Hi. I am using visual studio 2008 coding asp.net.vb

I have 20 images on my site, the image holders being named picbox1 picbox2 picbox3 ... picbox20.

I want to be able to address each picbox programmatically; pseudo code would look something like this

if myvar = 1 then
picbox(myvar).imageurl="XXXXXXX"
end if

Can this be done and if so how?

Ah sorry should have said, I need to do this server side as part of my vb code.

Thank you for all and any help.

A: 

Hi, I'm not sure if you want to do this from server side or client side, but client side is the best, just add a javascript method in image that looks like following:

var count=0;
setTimeout(1000,getImage);
function getImage()
{

   document.getElementById('image').src='image path'+'?count='+count;
}

this will do what you want to do!

lakhlaniprashant.blogspot.com
+1  A: 

You can loop through the control in your form like so:

    Dim count As Integer = 1
    For Each Control In form1.Controls
        If TypeOf Control Is Image Then
            Dim img As Image = CType(Control, Image)
            If img IsNot Nothing And img.ID = "picbox" & count.ToString() Then
                count = count + 1
                'Do something with picbox
            End If
        End If
    Next

Or you could just do a FindControl like so:

Dim img1 As Image = CType(form1.FindControl("picbox" & myvar.ToString()), Image)

img1.ImageUrl = "XXXX"

Aaron
Thanks for the answer!
simon