locked
Page Refresh or F5 - Duplicate Record - ADO .Net RRS feed

  • Question

  • User121568070 posted
    I have a Page that submits record to an Access table with autonumber as a contraint. After sucessful submission - the page would list the records. But if I do a Page Refresh or F5, a DUPLICATE record is created. Any Advice?
    Monday, November 1, 2004 1:02 PM

All replies

  • User-1280723201 posted
    My suggestion would be before inserting a record check whether the same record exists in the table. if yes, you can redirect to error page. Otherwise you can insert into the table. Hope it gives an idea on how to handle the situation.
    Monday, November 1, 2004 8:55 PM
  • User-1897028626 posted
    Check out this article about trapping the browser refresh event: http://www.microsoft.com/indonesia/msdn/BedrockAspNet.asp#bedrockas_topic2 Dino Esposito wrote a great artilce about trapping the browser refresh event to prevent resubmitting data ( or submitting data you do not want to submit ) but I read it at aspnetPro.com and you must be a subscriber to view the article. I think I have seen the same article somewhere else though. Google Dino Esposito and Trap Browser Refresh.
    Tuesday, November 2, 2004 2:28 PM
  • User-916330365 posted

    Hi, I find this solution, test and it's work Corectly :

    Source: http://stackoverflow.com/questions/718394/prevent-page-refresh-in-c

    // Send by : saber
    
    private bool _refreshState; 
    private bool _isRefresh;
    
    protected override void LoadViewState(object savedState)
    {
        object[] AllStates = (object[])savedState;
        base.LoadViewState(AllStates[0]);
        _refreshState = bool.Parse(AllStates[1].ToString());
        _isRefresh = _refreshState == bool.Parse(Session["__ISREFRESH"].ToString());
    }
    
    protected override object SaveViewState()
    {
        Session["__ISREFRESH"] = _refreshState;
        object[] AllStates = new object[2];
        AllStates[0] = base.SaveViewState();
        AllStates[1] = !(_refreshState);
        return AllStates;
    }
    
    protected void btn_Click(object sender, EventArgs e)
    {
        if (!_isRefresh)
            Response.Write(DateTime.Now.Millisecond.ToString());
    }
    Friday, May 27, 2011 12:19 PM