Peeyush
Peeyush

Reputation: 4828

how to check that any form field data is changed or not?

i am working on a asp.net web app in this application when customer logged in then his/her

personal details displayed in form fields (e.g. full name in name box ,age in age box etc) for getting data first i fetch the data from ms sql then assign them to ICustomer interface properties this interface is implemented by customer class.

And we also have a update button on customer information page so if without changing any information if a user click on update then unnecessary it will go to server and come back and the same data updated in database,so what i am trying to do is to just detect whether something changed in customer form then only update functionality should work.

i have two option

  1. just use Java script and detected the text change then unable update button.
  2. make a temporary reference of ICustomer and compare it to the older when then process by making something true or false.

so please suggest me the best approach for it or any other method.

if question is unclear then just comment on it i will explain more.

Upvotes: 2

Views: 3982

Answers (5)

Rahul Vaity
Rahul Vaity

Reputation: 21

the main problem with the Javascript option is that what if user changes value and again change to it's previous state in that case also it'll shows value changed.

Upvotes: 0

Daniel Szabo
Daniel Szabo

Reputation: 7281

If you're using the formview or detailsview control in your asp.net webpage, then you can use the OldValues property of the forms's itemupdating event to compare the values before posting to your database. I believe the form's viewstate must be enabled for this to work.

protected void myFormView_ItemUpdating(object sender, FormViewUpdateEventArgs e)
    {
        // Access the old values
        e.OldValues...

Here's a full example using the detailsview.

Upvotes: 5

Talha
Talha

Reputation: 19242

You should go to 2nd option if the size of your object is not very large as you have to store the old object before comparing to the new object of Icustomer to detect any changes. Otherwise use javascript to detect the changes on the text fields. but as you know its not very much reliable.

Upvotes: 1

RickNZ
RickNZ

Reputation: 18654

If you're using TextBox controls, one option is to use the TextChanged event to detect changes.

Upvotes: 2

Tomislav Markovski
Tomislav Markovski

Reputation: 12346

JavaScript may help you, but it's very unreliable. I say go with the second option. Store the ICustomer object in a Session variable and compare it with the new one.

Upvotes: 2

Related Questions