I am currently trying to store previous value of a Textbox and compare it with a new value when ontextchanged. However, the problem now is that, whenever i try to store the previous value for comparing, the value is null.

Is there a way to store previous value?

Here's the code that I've tried. Assuming tbDesc have a old value of Hello World, and I edit the textbox with Hello

ASPX

public string oldvalue = "";

protected void Page_Load(object sender, EventArgs e)
{
  oldvalue = tbDesc.Text;
}

protected void tbDesc_TextChanged(object sender, EventArgs e)
{
  string newvalue = tbDesc.Text;

        if (newvalue != oldvalue)
       {
        tbDesc.BackColor = Color.Yellow;
       }
        else
      {
        tbDesc.BackColor = Color.White;
    }
}

Related posts

Recent Viewed