Avoid duplicate insertion while page refresh

By Raja Baireddy

 

 Whenever you insert one record and after that if u click on refresh, again the same record insert once again. To avoid that we can use the following code in page load. And whereever u want simply u can use
if (!isrefresh){ }

 

 

 

 

if (Session["postid"] != null && ViewState["postid"] != null)

{

if (ViewState["postid"].ToString() != Session["postid"

].ToString()) 
 

 

 

IsPageRefresh =
 

 

true;
}
Session["postid"] = System.Guid.NewGuid().ToString();
ViewState["postid"] = Session["postid"];

Leave a Reply