Reputation: 8150
In a .net-webapplication, I have a module with the following code:
protected void SaveButton_Click(object sender, EventArgs e)
{
//..
itemRepository.Create(store, validFrom);
Item item = itemRepository.GetByStoreAndValidFrom(store, validFrom);
//..
}
An item is created by the repository and then fetched from the database.
Sometimes, f.ex. if the user clicks on the button twice very quickly, the following seems to happen:
Two program processes of this module (please correct if the term not right!) start very closely after each other. Two items are created and the first process crashes because there is more than one item available in the database.
Is there a good way to handle this problem? I thought about putting a javascript blocker into the interface (to prevent the second button click) but would be thankful for hints.
Upvotes: 1
Views: 100