Return to Snippet

Revision: 57136
at May 17, 2012 22:35 by satie83

Initial Code
// declare a global variable on page
private Boolean IsPageRefresh = false;
protected void Page_Load(object sender, EventArgs e)
    if (!IsPostBack)
        ViewState["postids"] = System.Guid.NewGuid().ToString();
        Session["postid"] = ViewState["postids"].ToString();
        TextBox1.Text = "Hi";

        if (ViewState["postids"].ToString() != Session["postid"].ToString())
            IsPageRefresh = true;
        Session["postid"] = System.Guid.NewGuid().ToString();
        ViewState["postids"] = Session["postid"];
protected void Button1_Click(object sender, EventArgs e)
    if (!IsPageRefresh) // check that page is not refreshed by browser.
        TextBox2.Text = TextBox1.Text + "@";


Initial URL

Initial Description
How do I prevent previously submitted form data from being reinserted into the database when the user presses the browser's Refresh button?
Although it is not possible due to unique key constraint available in tables but it is unnecessary go to other layer (data access, business layer).

Initial Title
IsPageRefresh in ASP .NET - Preventing previously submitted

Initial Tags
aspnet, c#

Initial Language