title: How to display the count of sent emails on the client while sending them on the server?
body: <p>How to display the count of sent emails on the client while sending them on the server with ASP.NET (C#)?</p>
  
  <p>So lets see my scenario:</p>
  
  <ul>
  <li>I have a button inside an UpdatePanel.</li>
  <li>This button should send some emails to my users (serverside).</li>
  <li><p>When I click on that button I also want to do some stuff like this:</p>
  
  <ol>
  <li>show a modal div with low opacity with a label at the center of
  it(the text of that label is "0").</li>
  <li>start sending mails.</li>
  <li>that label's text should update to reflect every sent email (this is a counter)(0->1->2->...)</li>
  <li>at the end of sending mails I want to hide that modal div</li>
  </ol></li>
  </ul>
  
  <p>And my code: </p>
  
  <h3>ASPX:</h3>
  
  <pre><code>&lt;asp:UpdateProgress ID="UpdateProgress1" runat="server"&gt;
    &lt;ProgressTemplate&gt;
      &lt;asp:Image ID="imgAjax" runat="server" ImageUrl="~/Images/ajax-loader.gif" /&gt;
    &lt;/ProgressTemplate&gt;
  &lt;/asp:UpdateProgress&gt;
  &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt;
    &lt;ContentTemplate&gt;
      &lt;div id="RadbtnSendEmails_Container"&gt;
        &lt;telerik:RadButton ID="RadbtnSendEmails" runat="server" EnableEmbeddedSkins="False"
          Skin="BlackByMe" Text="Send Mails" Width="150px" OnClick="RadbtnSendEmails_Click"
          Font-Bold="True" Font-Names="Tahoma" ValidationGroup="A"&gt;
        &lt;/telerik:RadButton&gt;
      &lt;/div&gt;
    &lt;/ContentTemplate&gt;
  &lt;/asp:UpdatePanel&gt;
  &lt;div id="OffDiv"&gt;
  &lt;/div&gt;
  &lt;div id="CounterContainer"&gt;
    &lt;asp:Image ID="imgWhiteCircle" runat="server" ImageUrl="~/Images/WhiteCircle.png" /&gt;
    &lt;asp:Label ID="lblCounter" runat="server" Text="0" Font-Bold="True"
      Font-Size="50px" ForeColor="#6600CC"&gt;
    &lt;/asp:Label&gt;
  &lt;/div&gt;
  </code></pre>
  
  <h3>C</h3>
  
  <pre><code>protected void RadbtnSendEmails_Click(object sender, EventArgs e) {
    ScriptManager.RegisterStartupScript(this, this.GetType(), "Show_Counter", 
      "Show_Counter();", true);
  
    //int Counter=0;
    //Send Mail Codes in for()
    //Counter++; in every send
    //Change that label'text to new counter -&gt; i do n't know how can i do that
  
    //ScriptManager.RegisterStartupScript(this, this.GetType(), "Hide_Counter", 
      "Hide_Counter();", true);
  }
  </code></pre>
  
  <p>However there is a problem with this C# codes:</p>
  
  <p>When I click on that button, the image inside UpdateProgress shows itself and after this block ends sending emails we can see the modal div, but not at the start of the process!</p>
  
  <p>Also, I don't know how to implement that counter! Should I jump from client-side code to server-side code or from server-side code to client-side code.</p>
  
  <p>Those email addresses are in a Sql Server 2008R2 database. So I have to run that part of the process server side.</p>
  
  <p>I really want to learn how fix this issue, and I think this scenario is nice, so please help me to get a good idea about that.</p>