Search code examples
.netchange-tracking

Check for changes in a ASP.net form


I want to check if there have been any changes to a form on my ASP.NET webpage, What are my options?

Should i check if the viewstate has changed or should create a flag in the code-behind, triggered by webcontrol events like TextChanged for Textboxes or SelectedIndexChanged for Dropdownlists?


Solution

  • You could store the sent values in attributes. Something like:

    Textbox1.Text = <Sent Text>
    Textbox1.Attributes.Add "OldText",Textbox1.Text
    

    On postback, you can compare:

    If Textbox1.Text <> Textbox1.Attributes("OldText") Then
       ' Text is different
    

    You would have to do that for every control in your form. Of course, you could write a procedure to do this in a more automatic way, like iterating through all your controls.