1

I have a page with different controls (checkboxes,textareas, ddls..etc), On pageload the data is loaded into controls.

What would be a good approach to check if the data was modified from the original data after the button was clicked. Using c#.

Thanks,

3
  • Do you want to know the appropriate event in the life cycle? Appropriate what?
    – Andre Pena
    Jul 5, 2012 at 19:48
  • sorry spelling mistake, meant to write: good approach
    – Benk
    Jul 5, 2012 at 19:51
  • @Ben you can try with viewstate or hidden input Jul 5, 2012 at 19:57

5 Answers 5

2

Hide the default content of controls in HiddenField. Check the last content of controls with comparing the values in hidden fields in ButtonClicked event.

1

If this is a web application I would look at Session Variables ,ViewState,etc which I personally prefer Session Variables If this is a Windows I would look at Properties there are a couple of ways you could do it. can you provide and example as to what type of data you are wanting to hold sounds like you are looking at creating something like a DELTA

2
  • this is a web app, I can use session variables, I have 20 fields, so you saying to check each field and compare to the session variable and see if it was changed?
    – Benk
    Jul 5, 2012 at 19:54
  • Session is an Object so you could lookup the Session.Add Method or you could create a HashFields too
    – MethodMan
    Jul 5, 2012 at 20:07
1

You can inherit from these controls and create custom controls. There you can create property to store your initial value. Later you can compare it to the current value and see if it is changed or not.

1

Are you doing this to check for concurrency? If so, I would recommend using the entity data model. It has built in features to check if a field has changed from the original. Here is a quick example how to use it:

http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/handling-concurrency-with-the-entity-framework-in-an-asp-net-mvc-application

3
1

You can use ViewState["Key"]

try with

1. In the load

ViewState["Key"] = texbox.Text;

2. Compare in the post the two values

1
  • I have 20 fields, so you saying to add 20 viewstate parameters and check each one on button click if it was changed?
    – Benk
    Jul 5, 2012 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.