How to implement locking in ASP.NET application?

I've an ASP.NET application. Two users logged in simultaneously and in a Grid page both users choose same record. User1 modifies some data and click submit button. User2 modifies data and click submit button. At this time I would like to show a Pop-up message saying that Another User (ie User1) modified that data. Upon clicking Ok button I would like to rollback the User2's transaction. How to achieve this. Please guide me.

It would be great if I get any sample application or code. Thanks.
LVL 16
Easwaran ParamasivamAsked:
Who is Participating?
rajapandian_81Connect With a Mentor Commented:

The easiest method is add one field "ModifiedDateTime" in database. When retrieving the record from database, get this field value also. Do your changes in grid. If other user has modified the record at this time, the retrieved value of "ModifiedDateTime" and database value of "ModifiedDateTime" will be different. So alert the user. If there is no datetime difference, update the record.
Easwaran ParamasivamAuthor Commented:
Welcome :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.