How to stop inserting data after refresh in asp.net

When you click refresh button it always do again the last action performed.you can stop inserting data for that page where you actually want to insert data once not again and again.just for example in registration page you have submit data once.if you submitting articles or posting answer you may have do it again and again remaining in same page.

so this the code i have used in a project to stop inserting data where you want to insert data once not again and again.

1.create a hidden field and add some code to form tag.

<form id="Form1" method="post" runat="server" onsubmit="var o=getElementById('__STATUSREFRESH');var i=Number(o.value);i++;o.value=i;">

            <input id="__STATUSREFRESH" type="hidden" value="1" name="__STATUSREFRESH" runat="server">

2. Add these code to serverside

private bool IsRefreshCheck;

private bool RefreshStamped;

private bool IsRefresh

        {

            get

            {

                if (!this.RefreshStamped)

                    this.IsRefreshCheck= checkRefresh();

                return this.IsRefreshCheck;

               

               

            }

        }

private bool checkRefresh()

        {

            this.RefreshStamped= true;

            string stampKey = String.Concat(this.ToString(), "_STATUSREFRESH");

            int prevStamp = getValue(this.Session[refreshCheck] as string);

            int stamp = getValue(this._STATUSREFRESH.Value);

            if (stamp > prevStamp) // Postback

            {

                this.Session[refreshCheck] = stamp.ToString();

                return false;

            }

            return true;

        }

//THEN CHECK

if (!this.IsRefreshCheck==true)//THERE WAS NO REFRESH BUTTON CLICKED if clicked then last action willnot performed

{

// DO THE ACTION

}

Comments