title: Prevent Page Refresh in C#
body: <p>Duplicate of <a href="https://stackoverflow.com/questions/716187/asp-net-button-event-on-refresh-fires-again-guid/716252#716252">Asp.Net Button Event on refresh fires again??? GUID?</a></p>
  
  <p>hello, ive a website and when a user click a button and the page postback, if the user refresh the Page or hit F5 the button method is called again.</p>
  
  <p>any one know some method to prevent page refresh with out redirect the page to the same page again ?</p>
  
  <p>something like if (page.isRefresh) or something... or if exist any javascript solution is better.</p>
  
  <p>this seen to works.... but when i refresh it does not postback but show the before value in the textbox</p>
  
  <p><a href="http://www.dotnetspider.com/resources/4040-IsPageRefresh-ASP-NET.aspx" rel="nofollow noreferrer">http://www.dotnetspider.com/resources/4040-IsPageRefresh-ASP-NET.aspx</a></p>
  
  <pre><code>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";
  
      }
      else
      {
          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 + "@";
  
      }
  }
  </code></pre>