Click here to Skip to main content
15,889,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Every one,
I have a aspx.cs page in my web application where i have a button. on this button click i have a loop (for(i=0;i<20;i++). I have a div with id (
). now i want to update div text in loop.

like when loop execute for i=1 then it div show (1 is complete) and so on to user.
like
C#
for (int i = 1; i <= cnt; i++)
       {
      divMsg.InnerHtml = "Error:" +i+ " is complete.";
}

means it show update during process. how i achieve this.
Posted
Comments
Debojyoti Saha 29-Oct-15 5:08am    
Use BackgroundWork class and Updatepanel for This type of task
Andy Lanng 29-Oct-15 5:14am    
There are several ways of achieving Server Sent Events (SSE). I use SignalR but that is because my events can occur any time and I have a limited number of users. SignalR requires a new connection per user per service.
Here's a question I posted on Stack Overflow regarding SSE that you may find more suitable: .Net Server-Sent Events using HttpHandler not working.

Other ways of achieving the same effect is using long-polling: Simple Long Polling Example with JavaScript and jQuery. This technique usually requires a reasonably short wait time but can be very effective.
Krunal Rohit 29-Oct-15 5:35am    
Well, loop will execute so fast that you'd be seeing the message like "0 is complete" and then suddenly "20 is complete".

-KR
ErBhati 31-Oct-15 5:03am    
hi krunal,
this loop is for testing purpose. but in my application it takes time to complete a the process.
ZurdoDev 29-Oct-15 7:56am    
First off, you need to understand how the web works. A user puts in a url to your page, the C# code executes on your server and generates html which is sent to the client and then you are no longer connected. So, to show progress on the client side you need to use client side code, javascript.

1 solution

Well, you can do something like:
JavaScript
$("#loader").show();
todo(); // your time-taking task
$("#loader").hide();

You can use any of the loading image from here: http://preloaders.net/[^], and set it in <div id="loader"></div>

-KR
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900