views:

37

answers:

3

I have an array of urls containing locations of pictures on page load. I need to show them to the user in an <asp:img> with a 5 second time interval.

Can this be done with <asp:timer>, or is there any way to do it?

A: 

Create for loop and iterate trough array, how else would you do it?

c0mrade
but how to iterate through array with 5 second time gap???
Asanka
@Asanka how big is your array
c0mrade
no more than 10 items
Asanka
@Asanka than the for loop will do for that
c0mrade
+1  A: 

Try using a javascript plugin for that. Coin slider is great for this.

Faisal
that's great if I have only images to iterate through. What if I need to change some details in other controls, for example say text in a label?
Asanka
I dont' quite get what you're asking. Can you please restate?
Faisal
what about updating labels after 5 seconds(not only images, which can be easily done using Coin Slider as you said...)
Asanka
In that case, check the answer by AlbertVanHalen.
Faisal
A: 
<asp:Image ID="image1" runat="server">

<script type="text/javascript">
var imgArray = ['1.png','2.png','3.png','4.png','5.png','6.png','7.png','8.png','9.png','10.png'], imgToShow = 0;

function showImage() {
   if(imgToShow > imgArray.length - 1)
      imgToShow = 0;

   document.getElementById("<%= image1.ClientID %>").src = imgArray[imgToShow++];
}

showImage();
window.setInterval(showImage, 5000);
</script>
AlbertVanHalen
hey!! thank you very much. This is really helpful to me to extend and update more fields rather than only images....
Asanka