Show current loop counter every 2 seconds using Ajax in ASP.Net

no_lah

New Member
I need to run a loop (a loop through records & take some action) on a button click event, I want to show current loop counter \[code\]i\[/code\] using UpdatePanel. it is not working for me I searched through net but count not find a similar example. It show the \[code\]lblCounter\[/code\] loop counter after completing the loop, while I need to show the \[code\]lblCounter\[/code\] for every counter. What is the best way to do even if I have to delay statement as show in the code.Code below is just an example. I would appreciate if some can help me with this example. I actually want to loop through each record in the table & send email to all user. No of user will not exceed more than 200 0r 300.While it is sending email I was to update client screen with the number of email that have done out, this is the basic thing that I want to achieve using update panel.Markup:\[code\]<asp:Button ID="btnLoop" runat="server" Text="Start" onclick="btnLoop_Click" /><br /><asp:UpdatePanel ID="updPanelNewsletterProgress" runat="server" UpdateMode="Conditional" > <ContentTemplate> <asp:Label ID="lblCounter" runat="server" Text=""></asp:Label><br /> </ContentTemplate></asp:UpdatePanel> \[/code\]Code:\[code\]protected void btnLoop_Click(object sender, EventArgs e){ for (int i = 0; i < 100; i++) { System.Threading.Thread.Sleep(2000); // take some action like send email to user XXX lblCounter.Text = "Counter " + i.ToString() + " of 100"; }}\[/code\]
 
Back
Top