Avoid Multiple Form Submits
Multiple form submits can result difficulties in web applications because of unexpected behaviors like multiple entries in database. Here is a solution to help you avoid multiple submits.
If you are submitting the page only once then you can use,
<form onsubmit="return Submit();">
And the method is like,<script type="text/javascript">
var flag = false;
function Submit()
{
if (flag)
{
return false;
}
else
{
flag = true;
return true;
}
}
</script>
For a single button you can use,btnSubmit.Attributes["onclick"] = "this.disabled=true;" +
GetPostBackEventReference(btnSubmit);
For pages with update panels multiple submit is a real problem as page is posting asynchronously or partially.In that scenario you can use Sys.WebForms.PageRequestManager for fixing the issue,<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequest);
function BeginRequest(sender, e)
{
e.get_postBackElement().disabled = true;
}
</script>
Revision number 2, Thursday, August 06, 2009 9:29:02 PM by mbanavige
You must Login to comment.
|
Fri, Aug 14, 2009 8:16 AM
by csharppointer
|
what does this statement do GetPostBackEventReference(btnSubmit);
|
|
Mon, Aug 24, 2009 4:45 AM
by friendster
|
http://msdn.microsoft.com/en-us/library/ms153110.aspx
|
|
Thu, Feb 11, 2010 9:38 PM
by ja
|
do you have a way to disable, remove history of back button. I really don't want the user click on the back button. I had try all method but seem not work for me.
|
|
Sun, Jun 10, 2012 2:00 AM
by malik.shafique
|
what will happen in case of validation controls used on page.
|