I am facing a problem with locking an asp.net page. We have a user profile page in which we need to lock that page for the user who opened it first. The details are as follows, There are many user profile records in database and we are passing the record number to querystring to open a particular page. The user clicks a linkbutton in a grid and opens the record in readonly mode. There is an edit button which enables all the controls and makes it available to user once he clicks it. The task is to lock the record to the user who clicks the edit button first.
Apart from this there are many scenarios like the user may navigate from the page or he may close the page in between. In these cases the record should be available to the other users. Please give me some possible approaches or examples of how to solve the scenario.
Thanks in advance
I've worked on a similar system and in our case we set a bit on the record in the database to indicate that it was being edited. However, unlike your case we were able to set the expectation with the end users of our system that they MUST click either 'Save' or 'Cancel' to flip the bit back over and allow editing of the record by other users. I'm honestly not totally sure how to handle the case in which a user abandons the page, though what comes to mind is to have a scheduled task that runs a sproc that will free the record if it has been locked for a certain period of time (this means you'd need a datetime field as well to indicate when the record was locked).