Image swapping using ajax (disjointed rollover)

Last post 11-19-2008 10:46 AM by magicjoef. 5 replies.

Sort Posts:

  • Image swapping using ajax (disjointed rollover)

    11-18-2008, 10:15 AM
    • Member
      90 point Member
    • magicjoef
    • Member since 02-26-2007, 12:32 PM
    • UK
    • Posts 178

    Hi, I wonder if anyone can point me in the right direction with this problem:

    I have a datalist of thumbnail images, and their URL is dynamically added to the asp:image control from a database.

    I have also got a large image being displayed on the page. I would like to be able to click on a thumbnail and for that to change the large image to the new one. I previously did this using JavaScript only, but now my images are being picked from a database that code has become redundant. I think it is called a disjointed rollover?

    Your help is gratefully received.

  • Re: Image swapping using ajax (disjointed rollover)

    11-18-2008, 10:45 AM
    Answer
    • Participant
      1,710 point Participant
    • Shocker-z
    • Member since 09-17-2007, 3:10 PM
    • Nottingham, England
    • Posts 347

     Personally i would stick with javascript option and pass the full image url to the javascript function so you may have somthing liek this (ruff and not tested)

    <img src="thumbnail.jpg" alt="" onMouseOver="SwapImage('fullimage.jpg')">

    Just populate the thumbnail SqapImage parameter when creating the page initially as you'll already be running some sort of repeater/loop to know what thumbnail image to show.

     

    Regards

    Liam

    If you've had a problem then someone else has too. Google is your friend. google for your topic title.
  • Re: Image swapping using ajax (disjointed rollover)

    11-18-2008, 11:31 AM
    • Member
      90 point Member
    • magicjoef
    • Member since 02-26-2007, 12:32 PM
    • UK
    • Posts 178

    Ah, I see! I'm not a java-diva either, so I hadn't thought of that. Seems like it could be a good idea.

    So I would databinding in my asp:image tag for my thumbnail which will give the JavaScript the value to use?

    I'll give it a try and see what happens, thanks for your time.

    Joe

  • Re: Image swapping using ajax (disjointed rollover)

    11-19-2008, 6:37 AM
    • Member
      90 point Member
    • magicjoef
    • Member since 02-26-2007, 12:32 PM
    • UK
    • Posts 178

    Hm, I'm struggling quite a bit with this one. Can anyone provide some details about how I can go about merging some JavaScript into my dynamic page.

    Thanks

  • Re: Image swapping using ajax (disjointed rollover)

    11-19-2008, 8:13 AM
    • Participant
      1,710 point Participant
    • Shocker-z
    • Member since 09-17-2007, 3:10 PM
    • Nottingham, England
    • Posts 347

     Could you show your code and your old static javascript method and we should be able to come up with somthing.

     

    Regards

    Liam

    If you've had a problem then someone else has too. Google is your friend. google for your topic title.
  • Re: Image swapping using ajax (disjointed rollover)

    11-19-2008, 10:46 AM
    Answer
    • Member
      90 point Member
    • magicjoef
    • Member since 02-26-2007, 12:32 PM
    • UK
    • Posts 178

    Sorry, I worked out I was looking through the code to paste why I was getting in a muddle!

    I've simplified everything, so my main large image has a name of 'largeImage'

    I am then using the ASP.NET Repeater control to generate my thumbnails like this:

                        <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSourceThumbs">
    <HeaderTemplate>
    <h3>IMAGES</h3>
    </HeaderTemplate>
    <ItemTemplate>
    <a href="#"><img src='<%# Eval("ImageThumb", "images/thumbs/{0}") %>' onclick="document.largeImage.src='<%# Eval("ImageURL", "images/projects/{0}") %>';" /></a>
    </ItemTemplate>
    </asp:Repeater>

    This binds my image url to display the thumbnail, and then passes the required full image url to the onclick event. This has actually cut down on my JavaScript from before. I'm going to do a bit of testing to see if it is robust. Can you spot any problems with this method do you think? It seems okay so far.

    Thanks for your reply,

    Joe

Page 1 of 1 (6 items)