Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8854363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:51:49+00:00 2026-06-14T13:51:49+00:00

I created an image element in web page. I am extracting image urls from

  • 0

I created an image element in web page. I am extracting image urls from database and wanted to set the url of the image element to these values with a gap of 5 seconds of interval each.

How can I achieve this?

here is my sample code…

RollingScreenBAL bal = new RollingScreenBAL();
DetailsForSlideShow[] details = bal.GetDetailsForSlideShow(username);
foreach (DetailsForSlideShow detail in details)
{
    imgSlideShow.Attributes["src"] = ResolveUrl(detail.GraphUrl);
    Thread.Sleep(detail.TimeInterval);
}

By the above code I am able to set the image url only for the first value that i am getting from database….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:51:50+00:00Added an answer on June 14, 2026 at 1:51 pm

    What you are describing seems much like a client-server with “push logic” from server using an extabilished, permanent communication. This is not possible to get working on the web. Last, using sleep events during a page processing, it’s not always a good idea, unless there are some specific reasons (i.e. to wait a specific resource to get available). Even when using an ajax update panel it’s always the client to trigger the event, leading to server.

    To have your slideshow, you have many options, I will show you two of them, but you can also use ready to use plugins, there are tons of examples on the web, just search for them.


    1- A quick and dirty solution, but hopefully for a short number of images. You can create a javascript array based on db content, and use it as if they were statically created for a simple slideshow javascript, and let it change through SetInterval js function.

    c# code:

    //
    // ... this is your code
    //
    RollingScreenBAL bal = new RollingScreenBAL();
    DetailsForSlideShow[] details = bal.GetDetailsForSlideShow(username);
    
    string script = "var myimg = new Array();\n";
    int i=0;
    foreach (DetailsForSlideShow detail in details)
    {
      script += "myimg[" + i.ToString() + "] = \"" + ResolveUrl(detail.GraphUrl) + "\";\n";
    }
    Page.ClientScript.RegisterClientScriptBlock(typeof(string), "arraykey", script, true);
    

    web page:

    [...]
    <div id="mydiv"><img src="" alt="" /></div>
    [...]
    

    This will render to web page to something like:

    var myimg = new Array();
    myimg[0] = "/path/img0.jpg";
    myimg[1] = "/path/img1.jpg";
    myimg[2] = "/path/img2.jpg";
    [...]
    

    Which you can later use/cycle with javascript:

    var curimg=0;
    function slideshow() {
        document.getElementById("mydiv").getElementsByTagName("img")[0].src = myimg[curimg];
        curimg++;
        if(curimg >= myimg.length) curimg=0;  //Restart from first image
    }
    

    and then start the slideshow, with a script at end of html (or on onload event in body)

      setTimeout(slideshow, 5000);
    

    note: you can generate/append also this script in c# RegisterClientScriptBlock as shown before, just change the “arraykey” value every time. More infos here: http://msdn.microsoft.com/it-it/library/bahh2fef%28v=vs.80%29.aspx


    2- A better solution is to use jquery’s ajax method to get “next image” from a c# web method.

    web page:

    [...]
    <div id="mydiv"><img src="" alt="" /></div>
    [...]
    

    javascript code:

    function slideshow() {
      $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        url: "/ajax.aspx/GetNextImage",
        dataType: "json",
        success: function (data) {
          //this changes the image on the web page
          $('#mydiv img').attr("src", data.d);
    
          //fires another sleep/image cycle
          setTimeout(slideshow(), 5000);
        },
        error: function (result) {
          alert(result.message);
        }
      });
    }
    
    $(document).ready(function () {
      //Kicks the slideshow
      slideshow();
    });
    

    cs code:

    [WebMethod]
    public static string GetNextImage()
    {
      //
      // ... this is your code
      //
      RollingScreenBAL bal = new RollingScreenBAL();
      DetailsForSlideShow[] details = bal.GetDetailsForSlideShow(username);
    
      //Someway get next image you need to display
      //So I assume you get 1 record only (from DB?)
      DetailsForSlideShow detail = details[0];
    
      //Last you can save last sent image name or index as per user...
      //I.e. you could use a Session variable, or move also this logic
      //to client side
      [...]
    
      //Send back to jquery call the image url
      return ResolveUrl(detail.GraphUrl);
    }
    

    note: if you are missing what jquery is, search the web for it, I’m sure it will help you a lot using javascript.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having trouble working grabbing a dynamically created image from this service: http://opsin.ch.cam.ac.uk/opsin/USER-STRUCTURE-TO-GENERATE.png Im
i have created one image but problem is that when i save image from
I created an .png image from a video using ffmpeg tool and i want
I have a web page where I create images from text by clicking a
I'm using JavaScript to create and remove elements from a web page. I've got
I've created a web page that lets you input some information and then draws
My homework is to create a web page that displays an image and a
I successfully created a WebGL texture from an image and drew it into a
I have a web page with a jpg image that the user draw an
Supposing I'm setting a background image for a web page in CSS like this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.