In this article I will explain with an example, how to prevent / avoid / stop Form Resubmission (Resubmit) when Refresh button clicked in Browser in ASP.Net.
The problem is that when browser refresh button or F5 or CTRL + F5 function keys are pressed, the last executed event is again executed.
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 (Avoid) Form Resubmission (Resubmit) when Refresh clicked in Browser in ASP.Net
The simplest resolution to solve this problem is redirecting the user after execution of insert or update operation. You can achieve the same in two ways
Redirect to some another page
After insert or update statement is executed you can redirect the user to some other page as described below
C#
private void InsertData()
{
    string strQuery = "insert into customers (CustomerID, CompanyName) values(@CustomerID, @CompanyName)";
    SqlCommand cmd = new SqlCommand(strQuery);
    cmd.Parameters.AddWithValue("@CustomerID", "A234");
    cmd.Parameters.AddWithValue("@CompanyName", "DCB");
    InsertUpdateData(cmd);
    Response.Redirect("~/Success.aspx");
}
 
VB.Net
Private Sub InsertData()
    Dim strQuery As String = "insert into customers (CustomerID, CompanyName) values(@CustomerID, @CompanyName)"
    Dim cmd As SqlCommand = New SqlCommand(strQuery)
    cmd.Parameters.AddWithValue("@CustomerID", "A234")
    cmd.Parameters.AddWithValue("@CompanyName", "DCB")
    InsertUpdateData(cmd)
    Response.Redirect("~/Success.aspx")
End Sub
 
Redirect to same page
After insert or update statement is executed you can redirect the user to the same page as described below
C#
private void InsertData()
{
    string strQuery = "insert into customers (CustomerID, CompanyName) values(@CustomerID, @CompanyName)";
    SqlCommand cmd = new SqlCommand(strQuery);
    cmd.Parameters.AddWithValue("@CustomerID", "A234");
    cmd.Parameters.AddWithValue("@CompanyName", "DCB");
    InsertUpdateData(cmd);
    Response.Redirect(Request.Url.AbsoluteUri);
}
 
VB.Net
Private Sub InsertData()
    Dim strQuery As String = "insert into customers (CustomerID, CompanyName) values(@CustomerID, @CompanyName)"
    Dim cmd As SqlCommand = New SqlCommand(strQuery)
    cmd.Parameters.AddWithValue("@CustomerID", "A234")
    cmd.Parameters.AddWithValue("@CompanyName", "DCB")
    InsertUpdateData(cmd)
    Response.Redirect(Request.Url.AbsoluteUri)
End Sub
 
Thus using the above simple technique you can easily stop or prevent duplicate inserts in your SQL Server Database in ASP.Net Application