This short tutorial will show you how to avoid multiple submissions from users by give an alert when user click or submit more than 1 time using JavaScript and asp net.
This function are suitable for ecommerce site or any pages that need do some registration or payment and etc.
Example situation, when you do a reservation for a flight and the online reservation service system didn't include the avoid multiple submit and the processing time for flight reservation system take more than your expect. You maybe thought that you didn't submit yet and when you click submit again. Maybe the online reservation system already helps you to book more than 1 ticket.
So, it is important to include this function to avoid you or your customer loose money.
Below is the code for this tutorial:
After you read and please give some comment (good and bad)
Javascript
script language=javascript >
var is_form_submited=0;
function enableJS()
{
document.testing.jsEnabled.value="yes";
return true;
}
function processInput()
{
if (is_form_submited==1)
{
alert("Your request has been submitted. please wait..");
return false;
}
enableJS();
is_form_submited=1;
return true;
}
.ASPX page
form id="testing" runat="server" onsubmit="processInput()">
asp:Button ID="Button1" runat="server" Text="Submit" />
input type="hidden" name="jsEnabled" value="no" />
.VB Code Behind Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Button1.Attributes.Add("onclick", "enableJS()")
End Sub
No comments:
Post a Comment