Introduction:
In this article,explains how to avoid submitting buttonclick more than once.
Main:
sometimes we clicked the web button more than once wrongly,simply its a careless mistake, but it will create a huge impact
in business perspective.
We can easily avoid this using the below simple technique,
Step 1:
I am setting the datetime in session variable at pageload,
Session["IsPageReady"] = Server.UrlEncode(System.Datetime.Now.ToString());
Session["IsPageReady"] = Server.UrlEncode(System.Datetime.Now.ToString()); |
Step 2:
We allready know,while refreshing page it will reach prerender,so iam going to set Session["IsPageReady"] into viewstate at page prerender,
ViewState["IsPageReadyl"] = Session["IsPageReady"].ToString();
ViewState["IsPageReadyl"] = Session["IsPageReady"].ToString(); |
Step 3:
In buttonclick,
if(Session["IsPageReady"].ToString() == ViewState["IsPageReadyl"].ToString())
{
Response.Write("Page allready Refreshed");
return 0;
}
else
{
ViewState["IsPageReadyl"] = Session["IsPageReady"].ToString();
//Continue yours coding part
}
if(Session["IsPageReady"].ToString() == ViewState["IsPageReadyl"].ToString()) { Response.Write("Page allready Refreshed"); return 0; } else { ViewState["IsPageReadyl"] = Session["IsPageReady"].ToString(); //Continue yours coding part } |
Conclusion:
Hope this helps,
Happy Coding.
Thank you for another great article. Where else could anyone get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information.