title: how to perform addition using a textbox
body: <p>I have a Text box. On button click event the value of Text box should be displayed in a label as result.
  On clicking the button again and giving some input in the Text box the input should get added to the result.
  I mean repeating the button clicks and providing input should get added o the result.
  How to perform this?</p>
  
  <p>I am still getting error </p>
  
  <pre><code>"System.FormatException: Input string was not in a correct format."
   Error is regarding: lblconsumed.Text = (int.Parse(lblconsumed.Text) + userValue).ToString();
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using WebApplication1.ServRef;
  using System.Configuration;
  using System.Data.SqlClient;
  using System.Data;
  
  namespace WebApplication1
  {
      public partial class WebForm1 : System.Web.UI.Page
      {
          ServRef.ProteinServiceClient sc = new ServRef.ProteinServiceClient();
          UserDetail userinfo = new UserDetail();
  
          protected void Page_Load(object sender, EventArgs e)
          {
              // ddlUser.DataSource = sc.AddUser(userinfo);
              BindUserDetails();
          }
  
          protected void BindUserDetails()
          {
              IList&lt;UserDetail&gt; objUserDetails = new List&lt;UserDetail&gt;();
              //objUserDetails = objService.GetUserDetails("");
  
              objUserDetails = sc.GetAllUser("");
  
              ddlUser.DataSource = objUserDetails;
              ddlUser.DataBind();
          }
  
  
  
  
          protected void btnAddUser_Click(object sender, EventArgs e)
          {
  
              userinfo.user_name = tbname.Text.Trim();
              userinfo.user_goal = Convert.ToInt32(tbgoal.Text.Trim());
              string result = sc.AddUser(userinfo);
  
              lblgoal.Text = Convert.ToString(userinfo.user_goal);
  
          }
  
          protected void Button2_Click(object sender, EventArgs e)
          {
              int userValue;
              if (int.TryParse(tbamount.Text, out userValue))
              {
                  lblconsumed.Text = (int.Parse(lblconsumed.Text) + userValue).ToString();
              }
          }
  
  
      }
  }`
  </code></pre>
  
  <p>My aspx page:</p>
  
  <pre><code> &lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %&gt;
  
  &lt;!DOCTYPE html&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;link href="Style.css" rel="stylesheet" /&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
          &lt;div id="main"&gt;
  
              &lt;h2&gt;Protein Tracker&lt;/h2&gt;
  
              &lt;div id="selectuser"&gt;
                  &lt;label for="select-users"&gt;Select a user&amp;nbsp: &lt;/label&gt;
                  &lt;asp:DropDownList ID="ddlUser" runat="server"
                       Width="60px" AutoPostBack="True" 
                       DataTextField="user_name" 
                      DataValueField="user_name" &gt;&lt;/asp:DropDownList&gt;
  
              &lt;/div&gt;
              &lt;hr /&gt;
              &lt;div id="adduser"&gt;
                  &lt;h2&gt;Add new user&lt;/h2&gt;
                  &lt;label for="name"&gt;User Name&amp;nbsp:&lt;/label&gt;
  
                  &lt;asp:TextBox ID="tbname" runat="server" style="margin-left: 10px"&gt;&lt;/asp:TextBox&gt;
                 &lt;br /&gt;&lt;br /&gt;
                   &lt;label for="goal"&gt;User Goal&amp;nbsp:&lt;/label&gt;
                  &lt;asp:TextBox ID="tbgoal" runat="server" style="margin-left: 20px"&gt;&lt;/asp:TextBox&gt;
  
                  &lt;br /&gt;&lt;br /&gt;
  
                  &lt;asp:Button ID="btnAddUser" runat="server" Text="Add" style="margin-left: 210px" OnClick="btnAddUser_Click" /&gt;
  
              &lt;/div&gt;
              &lt;hr /&gt;
              &lt;div id="addprotein"&gt;
                  &lt;h2&gt;Add protein&lt;/h2&gt;
                  &lt;label for="amount"&gt;Amount&amp;nbsp:&lt;/label&gt;
                  &lt;asp:TextBox ID="tbamount" runat="server"&gt;&lt;/asp:TextBox&gt;
                 &lt;br /&gt;
                  &lt;br /&gt;
                  &lt;asp:Button ID="Button2" runat="server" Text="Add" style="margin-left: 180px" OnClick="Button2_Click"/&gt;
  
              &lt;/div&gt;
              &lt;hr /&gt;
              &lt;div&gt;
                  &lt;p&gt;Total Consumed&amp;nbsp:&amp;nbsp &lt;asp:Label ID="lblconsumed" runat="server" Text=""&gt;&lt;/asp:Label&gt;&lt;/p&gt;
                  &lt;p&gt;Goal Set&amp;nbsp:&amp;nbsp  &lt;asp:Label ID="lblgoal" runat="server" Text=""&gt;&lt;/asp:Label&gt;&lt;/p&gt;
              &lt;/div&gt;
  
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>