What is the best way to update a button to disabled as soon as it is clicked?
An example would be very helpful
I tried the sample but it works well. The client event is executed immediately in the browser while Eval() or Call() are sent to the client in the response only after the request processing is completed.
Hi Luca
See attached example.
Whilst the JavaScript is set to true in the designer nothing happens on the client side
Change it to false in the designer and it starts working.
Hi Luca
Got to the bottom of it, the code below works
clientEvent1.Event = “execute”;
clientEvent1.JavaScript = “this.setEnabled(false);”;
this.button1.ClientEvents.Add(clientEvent1);
However if clientEvent1 is set to true
clientEvent1.JavaScript = “this.setEnabled(true);”;
It does not work when button1.Eval(“this.setEnabled(false);”); is called
Thanks
Ewan
Hi Luca
Works unless you call up the website on an android phone
Thanks
Ewan
You don’t need to call button.Update(), it’s never needed unless you are adding a custom property to a control. All you need is to add a client event like the sample that Levie posted.
clientEvent1.Event = "execute"; clientEvent1.JavaScript = "this.setEnabled(false);"; this.button1.ClientEvents.Add(clientEvent1);
It’s executed on the client the moment the button is clicked. It works for sure.
Hi Levie
The button still does not get updated to disabled after it has been clicked, until the spinner starts .
Same as using Button.Update()
Would EvalAysnc solve the issue?
Thanks
Ewan
Hi Ewan,
There are a couple different ways you can approach this issue.
As you click a normal button, the clicks are stored and processed in the order they arrive.
You can set dropDuplicateClicks: true in the Default.json file to prevent the clicks from queuing up and only firing when the first click has completed processing for the Button, CheckBox, RadioButton, and MenuItem controls)
You can also attach an “execute” handler in ClientEvents that calls “this.setEnabled(false);” to disable the control whenever it’s pressed on the client. You’ll need to update the server, setting Button.Enabled = false as well to reflect the change.
I’ve attached a sample project demonstrating these methods!
Does this help clarify?
Best,
Levie
Please login first to submit.