Thursday, 13 February 2014

PRevent Re-submission of Data on Browser reload in C#.NET

On .aspx page write take a hidden field:

<asp:HiddenField id="hdncheckreload" runat="server" />

On .cs page write a function to check whether it's first time call event or reloaded......

public bool notIsRefresh()
            bool retVal = false;
            if (Session["match"] == null || Session["match"].ToString() == hdncheckreload.Value)
                retVal = true;
            Session["match"] = DateTime.Now.Ticks;
            hdncheckreload.Value = Session["match"].ToString();
            return retVal;

call this method on event which is reloaded such as button click event, form submission etc...