Checking if the value of a textbox is changed or not

446 Views Asked by At

I have a textbox filled at the page load. I want to check the value of the textbox is changed or not in the "update" button press. Any solution? TIA.

1

There are 1 best solutions below

0
Albert D. Kallal On

Well, you could say use client side javascript.

But, you could also do this:

Say this text box:

            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <br />
            <asp:Button ID="Button1" runat="server" Text="Done - continue" OnClick="Button1_Click" />

And our code could be this:

   protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // code here to setup and load controls

            TextBox1.Text = "Dog";
            ViewState["TextBox1"] = "Dog";
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text != (string)ViewState["TextBox1"])
        {
            // then text box was changed
        }
    }