1

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.

2 Answers 2

1

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"

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

Comments

0

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!

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.