Prevent multiple clicks of a submit button (K2Button) in ASP.NET

  • 24 February 2022
  • 0 replies
  • 61 views

Userlevel 3
Badge +8
 

Prevent multiple clicks of a submit button (K2Button) in ASP.NET

KB000027

DOWNLOADS
DOWNLOADS
PRODUCT
K2.net 2003

SEE ALSO KB000008: Form level validation with K2.net™ 2003 SmartForms

LEGACY/ARCHIVED CONTENT
This article has been archived, and/or refers to legacy products, components or features. The content in this article is offered "as is" and will no longer be updated. Archived content is provided for reference purposes only. This content does not infer that the product, component or feature is supported, or that the product, component or feature will continue to function as described herein.

Hasty users often click multiple times on a submit button while the page is trying to connect to the K2.net™ 2003 Server to start a process or complete a K2.net™ client event.

 

The following code snippet can be inserted in your Page_Load event. It will disable the button immediately after it is clicked. This will give your application time to submit the request and prevent users from clicking the button repeatedly.

BONUS: This code is also applicable for the standard ASP.NET server control button, as the K2Button was inherited from this.
 
// Set up the Attribute property for the K2 button
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("if (typeof(Page_ClientValidate) == 'function') { ");
sb.Append("if (Page_ClientValidate() == false) { return false; }} ");
sb.Append("this.value = 'Busy...';"); // Caption for the button while doing the submit
sb.Append("this.disabled = true;");
sb.Append(this.Page.GetPostBackEventReference(this.K2Button1));
sb.Append(";");

// Add the Attribute property (inject client side code)
this.K2Button1.Attributes.Add("onclick", sb.ToString());
 

 


0 replies

Be the first to reply!

Reply