Getting updated value of Textbox in asp.net and c#
<p>I am searching and posting a lot in this issue,but could not get the satisfactory answer.I wanted to make sure that whenever I am making a call to server the value of Textbox should be the one which is the most updated one.</p>

<p>But when I am making the call to server the old value of the textbox persists.I know it is something to do with the postback,but I am not getting the exact way to get the updated value of textbox in my .cs file.</p>

<p>Please tell me what are the necessary steps that I should take to always get the latest value of the textbox.</p>

<p>Here is my code which is not working:</p>

<pre><code>protected void Page_Load(object sender, EventArgs e)
    {


        int contentID = Convert.ToInt32(Request.QueryString["contentid"]);
        if (contentID != 0)
        {
                if (!this.IsPostBack)
                {
                getContentBody(contentID);
                TextBox1.Text = content;
                msg_lbl.Text="Inside not PostBack";
                }
                else
                {
                getContentBody(contentID);
                TextBox1.Text = content;
                msg_lbl.Text="Inside PostBack";
                }
            }


            else
                Response.Write("Invalid URL for article");


    }



 public void getContentBody(int contentID)
    {
        try
        {
            //////////////Opening the connection///////////////

            mycon.Open();
            string str = "select content from content where contentID='" + contentID + "'";
            //Response.Write(str);
            MySqlCommand command1 = mycon.CreateCommand();
            command1.CommandText = str;
            dr = command1.ExecuteReader();
            if (dr.Read())
            {
                content = dr[0].ToString();
            }
        }
        catch (Exception ex)
        {
            Response.Write("Exception reading data" + ex);
        }
        finally
        {
            dr.Close();
            mycon.Close();
        }
    }

 protected void Button2_Click(object sender, EventArgs e)
    {
            //string textboxvalue = Request.Form[TextBox1.UniqueID];

            mycon.Open();
            string query = "update content set content='" +TextBox1.Text + "' where contentID= '"+contentID +"'";
            msg_lbl.Text = query;
            try
            {
                MySqlCommand command1 = mycon.CreateCommand();
                command1.CommandText = query;
                command1.ExecuteNonQuery();
                msg_lbl.Text = "text" + TextBox1.Text;
            }
            catch (Exception ex)
            {
                msg_lbl.Text = "Exception in saving data" + ex;
            }
            finally
            {
                mycon.Close();

            }


    }
</code></pre>

<p>Here is my aspx page code:</p>

<pre><code>      &lt;asp:TextBox ID="TextBox1" runat="server" Height="500px" 
             TextMode="MultiLine" Width="90%" AutoPostBack="True"&gt;&lt;/asp:TextBox&gt;
    &lt;/p&gt;
    &lt;p&gt;
        &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
        &lt;asp:Button ID="Button1" runat="server" Text="Delete post" /&gt;
        &amp;nbsp;
        &lt;asp:Button ID="Button2" runat="server" onclick="Button2_Click" 
            Text="Save changes" /&gt;
&amp;nbsp;
        &lt;asp:Button ID="Button3" runat="server" Text="Cancel" /&gt;
    &lt;/p&gt;
</code></pre>

<p>Please also tell me the reason why it is not working and how I can make it work.</p>

<p>Thanks,</p>

<p>Amandeep</p>
