Update button client side

Answered
0
0

What is the best way to update a button to disabled as soon as it is clicked?

An example would be very helpful

  • You must to post comments
Great Answer
0
0

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.

  • Ewan Walker
    Hi Luca thanks missed the fact that Eval was only updating the client at the end of the process
  • You must to post comments
0
0

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.

Attachment
  • You must to post comments
0
0

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

 

 

  • Levie (ITG)
    Hi Ewan, You disabled it and then tried to set the execute event to enable it, right? The “execute” event on the button isn’t going to fire when the button is disabled. It needs to be enabled to fire. Am I understanding the issue correctly? Best, Levie
  • Ewan Walker
    Hi Levie Please see Button.zip in my next answer. The issue is when you initialise the button (which is enabled) the JavaScript default has to be false in the designer, if you are using the same button click event to update itself client side. Hope this is clear Ewan
  • You must to post comments
0
0

Hi Luca

Works unless you call up the website on an android phone

Thanks

Ewan

  • You must to post comments
0
0

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.

  • You must to post comments
0
0

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

  • You must to post comments
0
0

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

  • You must to post comments
Showing 7 results
Your Answer

Please first to submit.