Solved

Label Text does not get updated

Posted on 2013-12-14
9
428 Views
Last Modified: 2013-12-20
I am trying to set the text of a label control based on a condition in a loop.

The condition is reached about 10 times during the loop.

The final text value is ->->->->->->->->->->->->->->

The label acts as a progress bar.

There is no error, but the label text does not get updated.

string strProgressChar = "->";
   
      for (int i = 0; i <=8000 ; i++)
       {
                intProgress++;
               
                if (intProgress == intProgressIncrement)  // increment is 300
                {
                    lblProgress.Text = lblProgress.Text + strProgressChar;  // Text is not updated
                    intProgress = 0;
                }

        }  // End  while ((line = sr.ReadLine()) != null)


Any help would be appreciated.

Thanks,
0
Comment
Question by:Dovberman
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 38

Expert Comment

by:Tom Beck
ID: 39718834
I'm not going to be much help here because I don't have access to VS for testing. When update bars do not show progress it's almost always because the processing thread you are attempting to report on is busy so it cannot also update the progress. In other words, it cannot do two things at once. You need to introduce a pause/update/resume logic at short intervals in your coding for the main process or add a second processing thread for the update (Google multi-threaded operations for asp.net) or you could do a progress bar using ajax for polling. Look here.You may need to provide the main process code to get the help you need.

That's my entire contribution to this question.
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 39718872
You can't do it like this in asp.net

in ASP.Net when you're running that process the entire thing is server side, the page doesn't reload again until after all of the server side code is finished running.

If you wanted to use the label as a progress bar you would need a web service of some kind.

See below for more information:
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_28283009.html
0
 

Author Comment

by:Dovberman
ID: 39719177
I thought I would need a delay step.  I will try the timer and provide feedback.

Thanks,
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 2

Expert Comment

by:DiscGolfDad
ID: 39719294
You can try either the .Refresh method of the label control, or you could invoke whatever your language's equivalent of "DoEvents" is.  I have to use DoEvents in VB programming, but overuse can be a problem, that's why I only use it at certain intervals using the MOD function, i.e. If intRec MOD 100 = 0 Then DoEvents
0
 

Author Comment

by:Dovberman
ID: 39719559
There is no .Refresh method for a label control.
0
 
LVL 2

Expert Comment

by:DiscGolfDad
ID: 39719921
Then instead try the Refresh method of the form.
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 39720314
If this is for asp.net there is no .refresh on the form.
0
 
LVL 8

Accepted Solution

by:
johny_bravo1 earned 300 total points
ID: 39723304
Well Asp.Net gives you more option for display a progress bar rather than using label.

If you are using UpdatePanel use UpdateProgress control.

Alternatively you can use javascript/ jquery, check below links for javascript

http://www.javascriptkit.com/script/script2/progressbar.shtml

http://jqueryui.com/progressbar/#default
0
 

Author Closing Comment

by:Dovberman
ID: 39731224
Thank you
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question