Answered by:
problem of rolling-execution about image-diaporama aspx - csharp c#

Question
-
User-458598543 posted
Hello,
I've got a problem of rolling-execution of [for loop] to show several images changed each [i value] condition. My function showed only the last image but the images before not showed. I put in [condition if] a [thread.sleep] or I try with DateTime.Now.Add(TimeSpan) but the function is uncorrected. Durant the sleeping thread, the page is loading with no image and page showing until the last image.
I hope your resolved.
Thanks you,
Marc-Antoine
Tuesday, July 30, 2019 5:54 PM
Answers
-
User-458598543 posted
Hello, in spite, I used javascript method to develop an automatical timer diaporama with the 'setInterval' fonction, otherwise it will be interessing to explore the 'timer' c# or 'system.threading' fonction.- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 15, 2019 9:21 AM
All replies
-
User475983607 posted
It sounds like a logical bug. Post your code or sample code that reproduces this issue if you need community debugging support.
Tuesday, July 30, 2019 5:57 PM -
User-458598543 posted
Follow the code causing the problem :
-------- the declaration :
string [] i = new string [] {"0","1","2"};
-------- the function :
foreach(string j in i)
{
if (j=="0")
{
img_information.ImageUrl = "/Images/01739550-photo-logo-amazon-com_20170730.png";
}
else if (j=="1")
{
System.Threading.Thread.Sleep(9000);
img_information.ImageUrl = "/Images/Euribassa_yomabeh_20180420.JPG";
}
else if (j=="2")
{
System.Threading.Thread.Sleep(9000);
img_information.ImageUrl = "/Images/Jobersplace_SouteneurCetJ_20171115.gif";
//j = "0";
}-------- the aspx page :
<div style="; left:0; width: 1254px; height:366px; background-color: white; text-align: center;" class="Class_figure">
<asp:Image id="img_information" runat="server" style="width: auto; height:300px;"></asp:Image>
<br />
<asp:Label ID="Label10" runat="server" CssClass="Class_Labels">Hallo 1 !</asp:Label>
<br />
<a id="a_Leffe" runat="server" class="class_a_pub">hallo 2 !</a>
</div>Well, the c# code is put on the same page of aspx page.
go to your help !
Marc-Antoine
Tuesday, July 30, 2019 6:08 PM -
User475983607 posted
You have one image control and therefore one image is displayed. Please take a moment to learn how to use the Visual studio debugger to verify your logic.
Use a data control if you wish to display multiple images.
public partial class default2 : System.Web.UI.Page { public string[] ImageList { get; private set; } protected void Page_Load(object sender, EventArgs e) { ImageList = new string[] { "/Images/01739550-photo-logo-amazon-com_20170730.png" , "/Images/Euribassa_yomabeh_20180420.JPG", "/Images/Jobersplace_SouteneurCetJ_20171115.gif" }; Repeater1.DataSource = ImageList; Repeater1.DataBind(); } }
<body> <form id="form1" runat="server"> <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <asp:Image ID="Image1" runat="server" ImageUrl='<%# Container.DataItem %>' /> </ItemTemplate> </asp:Repeater> </form> </body>
Data bond controls are covered in the docs.
https://docs.microsoft.com/en-us/aspnet/web-forms/overview/moving-to-aspnet-20/data-bound-controls
Tuesday, July 30, 2019 6:29 PM -
User-458598543 posted
Well, the purposed solution is probably satisfied but how is set the duration of image showing for the repeater control ? Otherwhise, I put the same code with my variables and the images aren't showing.
Otherwhise, could you say to me where is the logical or process bug, as I think when an algorithm is good, his son program should be ok !
Thanks you !
Tuesday, July 30, 2019 9:32 PM -
User665608656 posted
Hi Rednuts,
According to your requirement,I found that you want to show different pictures every other time, right?
If so, I recommend you to use setInterval in js to ahcieve this function, it will be much easier.
You could refer to this link : Window setInterval() Method
For more details, you could refer to the following code:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> <script src="../Scripts/jquery-3.3.1.min.js"></script> <script type="text/javascript"> $(function(){ var image="../Images1/pic1.png"; $("#img_information").attr("src",image);//Set the image displayed by default at the beginning
var i = 0; setInterval(ChangeImage,1000);//I have set one second every time to show each picture,you can change the time what you want
function ChangeImage(){ i++; if(i == 3)//When it loops to the last picture, set i to 0 and continue to show the first picture. { i = 0; }
//Here is to determine which image source you need to show. if(i == 0) { image= "../Images1/pic1.png"; }else if(i == 1){ image= "../Images1/pic2.png"; }else{ image= "../Images1/pic3.png"; }
$("#img_information").attr("src",image); } }); </script> </head> <body> <form id="form1" runat="server"> <div style="; left: 0; width: 1254px; height: 366px; background-color: white; text-align: center;" class="Class_figure"> <asp:Image ID="img_information" runat="server" Style="width: auto; height: 300px;"></asp:Image> <br /> <asp:Label ID="Label10" runat="server" CssClass="Class_Labels">Hallo 1 !</asp:Label> <br /> <a id="a_Leffe" runat="server" class="class_a_pub">hallo 2 !</a> </div> </form> </body> </html>The result of this work demo:
Best Regards,
YongQing.
Wednesday, July 31, 2019 6:03 AM -
User-458598543 posted
Hello, in spite, I used javascript method to develop an automatical timer diaporama with the 'setInterval' fonction, otherwise it will be interessing to explore the 'timer' c# or 'system.threading' fonction.- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 15, 2019 9:21 AM