title: Calculate total on TextBox's TextChanged() event in asp.Net
body: <p>I have a small application as below.</p>
  
  <p><img src="https://i.stack.imgur.com/Fr49v.jpg" alt="Screenshot"></p>
  
  <p>In this Material Rate and PO Total are read only fields. I want to calculate the total as per material quantity changes by formula (Total=Rate*Qty).</p>
  
  <p>I coded on Material Quantity's <code>TextChanged()</code> and also changed <code>AuotoPostBack</code> to <code>True</code></p>
  
  <p>Code I tried is as below:</p>
  
  <pre><code>protected void txtMQty_TextChanged(object sender, EventArgs e)
  {
   checkTotal();
  }
  
  //I am saving Rate in ViewState["Rate"] and retrieving here.
  private void checkTotal()
  {
   Rate = Convert.ToInt32(ViewState["Rate"]);
   txtMQty.Text = string.Empty;
   if (Rate &gt; 0 &amp;&amp; txtMQty.Text == string.Empty)
   {
    txtMRate.Text = Rate.ToString();
    txtTotal.Text = Rate.ToString();
   }
   Regex reg = new Regex("[^0-9]+$");
   var str = txtMQty.Text.ToString();
   str = reg.Replace(str, string.Empty);
   if (str.Length &gt; 0)
   {
   var qty = Convert.ToInt32(txtMQty.Text.ToString());
   int total = (Rate* qty);
   txtTotal.Text = total.ToString();
   }
   }
  </code></pre>
  
  <p>I am also using UpdatePanel to avoid round trip. My problem is when I input Quantity <code>txtMQty</code>'s <code>TextChaged()</code> event should fire but it's not firing. Not getting what's wrong.</p>
  
  <p>my .aspx page is as below.</p>
  
  <pre><code>&lt;tr&gt;
          &lt;td class="auto-style3"&gt;
              Material Quantity&lt;/td&gt;
          &lt;td class="auto-style4"&gt;
              &lt;asp:TextBox ID="txtMQty" runat="server" Width="87px" AutoPostBack="True" OnTextChanged="txtMQty_TextChanged"&gt;&lt;/asp:TextBox&gt;&lt;/td&gt;
          &lt;td&gt;
              &lt;asp:RequiredFieldValidator ID="RFVMQty" runat="server" ForeColor="Red" Display="Dynamic" ControlToValidate="txtMQty" ErrorMessage="Please provide Material Quantity" ValidationGroup="CreateVal"&gt;&lt;/asp:RequiredFieldValidator&gt;
              &lt;asp:RegularExpressionValidator ID="REVMQty" runat="server" ForeColor="Red" Display="Dynamic" ControlToValidate="txtMQty" ErrorMessage="Please provide proper Quantity in number format" ValidationExpression="^\d+$" ValidationGroup="CreateVal"&gt;&lt;/asp:RegularExpressionValidator&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
   &lt;tr&gt;
          &lt;td class="auto-style3"&gt;Material Rate&lt;/td&gt;
          &lt;td class="auto-style4"&gt;
              &lt;asp:UpdatePanel ID="UpdateRate" runat="server"&gt;
                  &lt;Triggers&gt;
                      &lt;asp:AsyncPostBackTrigger ControlID="txtMQty" EventName="TextChanged" /&gt;
                  &lt;/Triggers&gt;
                  &lt;ContentTemplate&gt;
              &lt;asp:TextBox ID="txtMRate" runat="server" Width="87px" ReadOnly="True"&gt;&lt;/asp:TextBox&gt;
                      &lt;/ContentTemplate&gt;
          &lt;/asp:UpdatePanel&gt;
                      &lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;
              PO Total
          &lt;/td&gt;
          &lt;td class="auto-style4"&gt;
              &lt;asp:UpdatePanel ID="UpdateTotal" runat="server"&gt;
                  &lt;Triggers&gt;
                      &lt;asp:AsyncPostBackTrigger ControlID="txtMQty" EventName="TextChanged" /&gt;
                  &lt;/Triggers&gt;
                  &lt;ContentTemplate&gt;
              &lt;asp:TextBox ID="txtTotal" runat="server" Width="87px" ReadOnly="True"&gt;&lt;/asp:TextBox&gt;
                      &lt;/ContentTemplate&gt;
          &lt;/asp:UpdatePanel&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
  </code></pre>