Header add

In this article we will learn about how to Prevent Duplicate(Double) Inserts when Page is refreshed in ASP.Net. This example we discuss how to prevent / avoid / stop duplicate (double) insertion of record on Page refresh in ASP.Net using C#.

Duplicate inserts or double updates occur when a Page is refreshed which causes Form re-submission and in turn causing re-execution of the last executed operation.


What cause the issue?

The problem is that when browser refresh button or F5 or CTRL + F5 function keys are pressed, the last executed event is again executed and a warning popup comes up which warns against Form resubmission.

For example, if you have a Form submission on Button click and after clicking button, Page is refreshed by the user then the Form is resubmitted and again same event gets called.

prevent duplicate

How to get rid of the issue?

Following are the two solutions to the above problem.
  • Redirection to other Page.
  • Redirection to same Page.
Examples

Below are the examples of the above two solutions. In the following example, an INSERT statement is executed and after that the necessary redirection is performed.

User is redirected to other page

Once the Database operation is completed i.e. INSERT or UPDATE, a redirection is performed to other Page. Once the Page is redirected it is impossible for User to perform re-submission of the Form.




User is redirected to same page

Once the Database operation is completed i.e. INSERT or UPDATE, a redirection is performed to same Page. Once the Page is redirected, it is impossible for User to perform re-submission of the Form.



So using the above two examples we can get resolve the issue.

Post a Comment

Previous Post Next Post