This has got to be easy, but has got me stumped.
How do I change an element on screen several times in one function?
I want to change a label to read something like “starting…” at the beginning of my function, then go away and do some stuff and then change the label to “finished” at the end.
As an illustration why does the following code:
errorMessage.Text = "Three...";
System.Threading.Thread.Sleep(1000);
errorMessage.Text = "Two...";
System.Threading.Thread.Sleep(1000);
errorMessage.Text = "One...";
System.Threading.Thread.Sleep(1000);
errorMessage.Text = "Go!";
System.Threading.Thread.Sleep(1000);
Just pause for 4 seconds and then change the label text to “Go!” rather than counting down?
TIA
Ben
The reason that your code only updates the screen once is that it is running inside of a single postback. At the end of the postback, HTML is rendered in returned to the browser for display.
Updating the page multiple times during a postback actually isn’t easy. But for what you’re doing, there is an easier solution. Use JavaScript to change the caption to “Starting…” at the beginning of the request, and then have the method return “Finished.”