Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6742783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:53:03+00:00 2026-05-26T11:53:03+00:00

I am searching and posting a lot in this issue,but could not get the

  • 0

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.

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.

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

Here is my code which is not working:

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();

            }


    }

Here is my aspx page code:

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

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

Thanks,

Amandeep

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:53:04+00:00Added an answer on May 26, 2026 at 11:53 am

    According to the ASP.NET’s life cycle, Page_Load executes before Button2_Click, so you have to show your updated text in the Button2_Click:

    protected void Page_Load(object sender, EventArgs e)
    {
    
    
        contentID = Convert.ToInt32(Request.QueryString["contentid"]);
        if (contentID != 0)
        {
            if (!this.IsPostBack)
            {
                getContentBody(contentID);
                TextBox1.Text = content;
                msg_lbl.Text = "Inside not 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();
            getContentBody(contentID);
            TextBox1.Text = content;
    
            msg_lbl.Text = "text" + TextBox1.Text;
        }
        catch (Exception ex)
        {
            msg_lbl.Text = "Exception in saving data" + ex;
        }
        finally
        {
            mycon.Close();
    
        }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not sure that's the right plattform asking this question. I'm searching a solution
I'm really posting this question so that others searching for the answer can find
I am really posting this out of desperation after searching around a lot for
Searching here I found that this question was already asked , but I think
Before posting I've searched a lot but I've not found what exactly I was
I have tried searching for an answer to this but I cannot find anything
I implemented the template.master technique described by Brad Wilson in this posting but I
I do not know if this the correct forum to ask this question but
I have tried solving this problem by posting other related questions here that focused
After hours of searching, finding similar threads and still not being able to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.