title: Prevent page re-submission after refresh asp.net
body: <p>I have a <code>Ajax</code> enabled asp form on which user can submit data. </p>
  
  <p>It works fine but when he/she presses <kbd>f5</kbd> or refresh page, form resubmits. This is a common question and duplicate as well.</p>
  
  <p>I have read so many questions on different forums about this problem and implemented some but problem still exists. </p>
  
  <p>I cant do redirection of page as per client requirement. I have taken reference from <a href="https://stackoverflow.com/questions/8470721/handle-page-refresh-in-asp-net">this question</a>. It worked fine on local machine but when I deployed page was not submitting even once. I gave some of my effort too, as follows`</p>
  
  <pre><code>HiddenField hf = new HiddenField();
  
   protected void Page_Load(object sender, EventArgs e)
      { 
  
          if (!IsPostBack)
          {
             createToken();    //to check page is refreshed
          }
  
      }
  
  public void createToken()
      {
          string token = System.Guid.NewGuid().ToString();
          Session["token"] = token;
          hf.Value = token;
      }
      private bool TokenIsValid()
      {
          string expectedToken = (string)Session["token"];
          if (expectedToken == null)
              return false;
  
          string actualToken = hf.Value;
  
          return expectedToken == actualToken;
      }
  
   protected void btnSubmit_Click(object sender, EventArgs e)
      {
          try
          {
              if (TokenIsValid()) // check that page is not refreshed by browser.
              {
                  //insert logic
          }}
  
          catch (Exception ex)
          {
  
  
          }
  </code></pre>
  
  <p>there is a <code>Dropdownlist</code> which is causing big problem of autopostback and autopostback can't be disable so value of hidden field is flushing out. I have no idea how to prevent resubmission.</p>