for my Winform applications I have used ClickSuppressor so that pereventing multiple action by pressing button twice or more. I am wondering what about the WebForms and MVC applications? Do we also need to use ClickSuppressor in this kind of projects?
using (new MyClass.ClickSuppressor(this))
{
try
{
//my action code i.e. add record
}
}
MyClass:
/// <summary>
/// Stops to queue event in order to prevent from "multiple click" when adding a new record.
/// </summary>
internal class ClickSuppressor : IDisposable
{
private Control mCtrl;
public ClickSuppressor(Control ctrl)
{
mCtrl = ctrl;
mCtrl.Enabled = false;
mCtrl.Update();
}
public void Dispose()
{
Application.DoEvents();
/* Or this:
MethodInfo mi = typeof(Control).GetMethod("RemovePendingMessages", BindingFlags.Instance | BindingFlags.NonPublic);
mi.Invoke(mCtrl, new object[] { 0x201, 0x203 });
mi.Invoke(mCtrl.Parent, new object[] { 0x201, 0x203 });
*/
if (!mCtrl.IsDisposed) mCtrl.Enabled = true;
}
}
This needs to be done in the browser with scripts.
Set the disabled attribute on the element to "disabled" when it is clicked:
<button class="singleClick">
The jQuery:
$(".singleClick").on("click", function(){
this.attr("disabled", "disabled");
});
You can remove the disabled status later with:
$(element).removeAttr("disabled");