IsPageRefresh in ASP .NET

This article, I will explains IsPageRefresh which is not provided by dot net but we can do this to check for either page is refresh or button clicked. Find the code for IsPageRefresh in ASP .NET

Learn IsPageRefresh in ASP .NET code and steps

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).


// 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 + "@";



Author: Muhammad Usman Iftikhar13 Oct 2008 Member Level: Bronze   Points : 0

Great work buddy.

Author: Vinod Kumar Gupta03 Jan 2010 Member Level: Bronze   Points : 0

very good article

Guest Author: sachin kumar11 Dec 2011

This solution working for me.You done great job but i could not understand hows change values of view state or session when page is refreshed. can u help me?

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: