I have a label that I would like to update with the current operation being done in a button's click event. Sample code:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Process 1....
 lblProcess.Text = "Now processing process1"
 'Process 2....
 lblProcess.Text = "Now processing process2"
'Process 3....
 lblProcess.Text = "Now processing process3"
End Sub

I have tried placing the label inside an update panel but it doesn't work. It only displays the last process. I have also tried calling a Javascript function to update the label.text but still no go.

What would be the best way to achieve this? Please help..

Thanks in advance.

Recommended Answers

All 4 Replies

After setting the label call Application.DoEvents. Your process does not take the time to update the GUI when it's running. Calling this function handles some events, so you will see the changes. Note that this of course slows down your processing.

this is a web app so I tried calling System.Windows.Forms.DoEvents() after each label text update, but still the same results.

Oh, then that doesn't work.

Well I think you have to add or do this as conditions so that for each states process it can update the label with the current process.

To do this I think you will have to add the timer on your project, I know someone may come with another Idea but this is how I use to track things even events. On your button you will have to remove those codes and just enter the code to start the timer so that it can start monitoring or tracking, than on your timer you can enter code to validate your label. Let say you are processing the or you are just reading names and surnames and ages, now let say you will be starting by reading names so you can write a code that will check if the reader has started reading if the reader has started than you can update the label that the first process is now running and then check if the reader has completed reading and also If the reader has completed reading than you can update the label and let say you will say Done proess 1 and then because the first process is done so it has to start the second process of reading surnames if you like you can make it sleep for a while before it start the next process, This is a very fist process if you will let the timer process it for you. you can then go on and on with your processes and update the label as soon as the process starts.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.