title: WebFroms How to refresh listbox in loop
body: <p>Is there way to update listbox in loop? I have an updatepanel with a listbox.</p>
  
  <pre><code>&lt;asp:UpdatePanel ID="UpdatePanel" runat="server"&gt;
      &lt;Triggers&gt;
          &lt;asp:AsyncPostBackTrigger ControlID="updateButton" EventName="Click"/&gt;
      &lt;/Triggers&gt;
      &lt;ContentTemplate&gt;
          &lt;asp:ListBox ID="lbUpdatedCompanies" runat="server" Height="300px" style="margin-top: 0px" Width="374px"&gt;&lt;/asp:ListBox&gt;
          &lt;br/&gt;
          &lt;asp:Button ID="updateButton" runat="server" OnClick="UpdateButtonClick" Text="Обновить"/&gt;
      &lt;/ContentTemplate&gt;
  &lt;/asp:UpdatePanel&gt;
  
  &lt;asp:UpdateProgress ID="UpdateProgress" runat="server" AssociatedUpdatePanelID="UpdatePanel"&gt;
      &lt;ProgressTemplate&gt;
          &lt;img src="../Icons/loading_spinner.gif" style="height: 60px; width: 65px" alt=""/&gt;
      &lt;/ProgressTemplate&gt;
  &lt;/asp:UpdateProgress&gt;
  </code></pre>
  
  <p>On button click I'm trying to add items to listbox in loop:</p>
  
  <pre><code>foreach (var company in companies)
  {
      lbUpdatedCompanies.Items.Add(company.NAME);
      Thread.Sleep(1000);
  }
  </code></pre>
  
  <p>But the <code>listbox</code> shows changes after loop exit when all items are added</p>