Click here to Skip to main content
15,914,419 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi
Does anyone have any Idea how I change the value of a label in every loop

VB
Protected Sub BtnUpdateLbl_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnUpdateLbl.Click
      For i As Integer = 0 To 20
           Me.lblChange.Text = i
           Threading.Thread.Sleep(1000)
           Me.UpdatePanel1.Update()
      Next
End Sub


I only get the last value of the loop.

I was thinking if theirs other way to achieve this scenario.

I was planning to use it on a progress bar so that the user will have idea of the current amount being inserted/Updated to that database.
Posted

1 solution

You can't do this directly in C# in ASP.Net. The reason is the web is a disconnected medium. Meaning that when a user clicks a button on your page a message is sent to your webserver where your C# code runs. All of your C# codes runs and ends up generating HTML that is then sent back to the client. This is why you only see the last one. The web does not work at all like windows forms.

What you want is to google for examples of how to show progress in ASP.Net. You'll need to kick off the process with jquery's .ajax() instead of a postback like you have now. That way you can query for the current status or from the client side process one at a time. You'll need to rethink what it is you are trying to do.
 
Share this answer
 

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