title: Updating label text several times during click event using ASP.Net
body: <p>I have a simple application that is written in C# using VS2012, in a web forms application. </p>
  
  <p>There is one button that starts the processing and I would like to give the user updates to the progress of the processing by putting some text in a Label.  I thought I could put the Label control in an UpdatePanel and then during the Button click event trigger the change in the Label text by calling the UpdatePanel Update() method.  However, the only time the label text changes is after the click event completes and the Label text is displayed, 'Process complete'.</p>
  
  <p>This is my xml:</p>
  
  <p>
        
        
              
        
        
  <br>
     </p>
  
  <p>This is the code behind:</p>
  
  <pre><code>protected void btnCreateFiles_Click(object sender, EventArgs e)
      {
          //Do some stuff
  
          //Show the message that the application is processing
          lblCaption.Text = "Processing...updating label data";
          ProgressUpdatePanel.ContentTemplateContainer.Controls.Add(lblCaption);
          ProgressUpdatePanel.Update();      
  
          //Call to database to insert labels
          //Call to database to get the labels 
  
          lblCaption.Text = "Processing...creating label files.";
          ProgressUpdatePanel.ContentTemplateContainer.Controls.Add(lblCaption);
          ProgressUpdatePanel.Update();   
  
         //Create Text files from data
  
          lblCaption.Text = "Processing...updating label counts.";
          ProgressUpdatePanel.ContentTemplateContainer.Controls.Add(lblCaption);
          ProgressUpdatePanel.Update();   
  
          //Database call to insert count records
          //Create file of count records
  
          lblCaption.Text = "Processing...completed.";
          ProgressUpdatePanel.ContentTemplateContainer.Controls.Add(lblCaption);
          ProgressUpdatePanel.Update();   
      }
  </code></pre>
  
  <p>The only text displayed is the last update..."Processing...completed."</p>
  
  <p>Why won't the other updates trigger the label text to be changed?</p>
  
  <p>Thanks</p>
  
  <p><strong>UPDATED REQUIREMENTS</strong></p>
  
  <p>I have changed my requirements a little.  Instead of multiple updates. I added a label in the Progress Template to display an initial message when the processing starts and then another message using the lblCaption label when the processing completes. However, when the button is clicked a second time, both of the messages are shown:  'Please wait while the files are created...' and 'Processing...completed'. </p>
  
  <p>How do I reset the text in the Progress Template to only display the 'Please wait...' message and NOT the 'Processing...complete' message also?</p>
  
  <p>This is the aspx file now:
  
  
  
   <br>
       <br>
  
  
  </p>
  
  <p><br>
  
         </p>
  
  <p>Now the Button Event handler method looks like this:</p>
  
  <pre><code>protected void btnCreateFiles_Click(object sender, EventArgs e)
          {
              //All of the processing is done here...
  
              //This works correctly the first time a user click the button
              //But the second time, this text remains and the 'Please wait...' text from the lblProgress label
              // is added above this text.
              ProgressUpdatePanel.ContentTemplateContainer.Controls.Add(lblCaption);
              ProgressUpdatePanel.Update();   
              lblCaption.Text = "Processing...completed.";
  
          }
  </code></pre>
  
  <p><strong>UPDATE</strong>
  I have tried the following to clear the text in the label, lblCaption. I have stepped thru the code and this code is executed for the label text is not cleared.<br>
  I tried reseting the label in the Page_Load() method as shown below:</p>
  
  <pre><code> protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              txtBoxEnvironment.Text = CurrentEnvironment;
              DAL.setConnectionString(CurrentEnvironment);
          }
          ProgressUpdatePanel.ContentTemplateContainer.Controls.Add(lblCaption);
          ProgressUpdatePanel.Update();   
          lblCaption.Text = "";
      }
  </code></pre>
  
  <p>I have removed the ProgressUpatePanel methods and have tried just setting the label text and it is not reset.</p>
  
  <p>What am I missing?</p>