zeex
zeex

Reputation: 1

Prevent Duplicate Insertion on DB When page refresh - Asp.net

(ASP.NET) How do i prevent duplicate records insertion in my database when user refreshs the page after post back. i know it can handle by redirecting the page. it and also handle through the check if same entry exists inside the stored procedure. but this wont full fill requirement sometime. i just want to know is there any other good practice instead redirecting the page. (I know it can also handle using AJAX, but i am not using AJAX)

Upvotes: 0

Views: 939

Answers (2)

Dave
Dave

Reputation: 8451

You can use the Page.IsPostBack property

private void Page_Load()
{
    if (!IsPostBack)
    {
        //logic 
    }
}

In the code example above, if the page is a postback then no code would be executed (the logic).

Upvotes: 0

Csharp
Csharp

Reputation: 2982

Try this

if (!IsPostBack)
        {
            do something

        }

Upvotes: 1

Related Questions