Solved

Image change in asp.NET/vb.NET

Posted on 2011-09-25
7
189 Views
Last Modified: 2012-05-12
I want to write a script for image changing in vb.NET/Asp.NEt.
Two images should be changing one after another after every 15  seconds or so.

Urgently required
0
Comment
Question by:Ammar Iqbal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36596002
your first image :
<asp:Image ID="Image1" runat="server" src="http://img39.imageshack.us/img39/2684/onlyinmexico69970146999.jpg" />

Open in new window

put the following in head section :
<script language="javascript" type="text/javascript">
    var slides = new Array(3);

    slides[0] = "http://img39.imageshack.us/img39/2684/onlyinmexico69970146999.jpg";
    slides[1] = "http://t0.gstatic.com/images?q=tbn:ANd9GcTitMd9yRepodcddFlBWdyj9NnmJeMxHTkECm7AuD7-25MVDJmeSFk_-ulHPA";
    slides[2] = "http://1.bp.blogspot.com/__gXsZ7-eRVw/SaXDuNBJK9I/AAAAAAAAS4g/fwXCAwq2bwY/s320/1711275404.jpg";

    var counter = 0;

    function imageChange() {
        counter++;
        if (counter == slides.length)
            counter = 0;
        document.getElementById("<%= Image1.ClientID %>").src = slides[counter];
    }

    setInterval(function () { imageChange() }, 15 * 1000);

</script>

Open in new window

Test page :
<%@ Page Title="Page d'accueil" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script language="javascript" type="text/javascript">
    var slides = new Array(3);

    slides[0] = "http://img39.imageshack.us/img39/2684/onlyinmexico69970146999.jpg";
    slides[1] = "http://t0.gstatic.com/images?q=tbn:ANd9GcTitMd9yRepodcddFlBWdyj9NnmJeMxHTkECm7AuD7-25MVDJmeSFk_-ulHPA";
    slides[2] = "http://1.bp.blogspot.com/__gXsZ7-eRVw/SaXDuNBJK9I/AAAAAAAAS4g/fwXCAwq2bwY/s320/1711275404.jpg";

    var counter = 0;

    function imageChange() {
        counter++;
        if (counter == slides.length)
            counter = 0;
        document.getElementById("<%= Image1.ClientID %>").src = slides[counter];
    }

    setInterval(function () { imageChange() }, 15 * 1000);

</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Image ID="Image1" runat="server" src="http://img39.imageshack.us/img39/2684/onlyinmexico69970146999.jpg" />
</asp:Content>

Open in new window

0
 
LVL 1

Author Comment

by:Ammar Iqbal
ID: 36596035
<asp:Image ID="Image1"  runat="server" Width="805px" Height="370px"  ImageUrl="~/Web_Public/Portal/Deloitte/Images/Morgenfuglene_banner_01.jpg" />


I am not getting the second image , i stead I get only cross  in the iamge section. I have palced thsi script in "Content 1 " section
               
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36596049
if you have cross image it's because your image path is wrong of course

did you try the code without any modification? it's a good start and it work fine
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 1

Author Comment

by:Ammar Iqbal
ID: 36596135
i have tried but iam not getting iamge 1 back. i want that two image should swap eanch continuously at a certain time intyerval.

like this img1,img2,img1,img2.......
0
 
LVL 1

Author Comment

by:Ammar Iqbal
ID: 36596169
thanx, its working.. how to increase the time interval
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36596173
If you can't see image1 you probably don't haver internet connexion or you change the path of the image...
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36596183
SetInterval
Yiu ask for 15s
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question