[SOLVED] Textbox KeyPressEventHandler e.Handled = true doesn't work

Answered Closed

Textbox works fine, but if I try to cancel some char input with

e.Handled = true

it doesn’t work.

Can I handle events inside objects with JavaScript?

  • You must to post comments
Best Answer

Hello Takashi,

Keyboard events, like all events in Wisej, are routed to the server asynchronously. The Handled property is useful on the server side when managing the OnKeyDown/Up/Press events to signal that a child has handled the key. However, this has no effect on the client,  unless you actually change the Text property to trigger a client update – I wouldn’t recommend this approach unless really necessary.

If you want to handle keys as they are typed and be able to stop the browser from processing the key you have to do it on the client using the JavaScript provider. It’s quite easy with Wisej. I have attached a sample project for you to use as a reference and a screen shot below of the script editor.

Download the sample



  • Drop the JavaScript component on the page or window. This will add the JavaScript and JavaScriptSource property to all controls.
  • You can either type the javascript code in JavaScript, or select a .js file in JavaScriptSource.
  • The javascript runs in the widget’s context: this = widget, see code above. It runs only once when  the page is loaded or reloaded.

Keeping the script above as a reference, we attach the “keypress” handler and handle the event. To stop it from both bubbling and “defaulting” use e.stop(). Otherwise you can use e.stopBubbling() and e.preventDefault().

When you work directly in javascript we enter the qooxdoo realm. The full API is here: http://demo.qooxdoo.org/current/apiviewer/#qx


  • ITG Admin
    I’d like to add that in Wisej there are other ways to invoke javascript from the server in addition to the JavaScript provider. You can call Invoke() on any control and pass either a full script or a function name and arguments. See the overloads. The script always runs in the context of the control you invoked it on: “this” refers to the javascript widget. i.e. this.button1.Invoke(“hide”) will hide the client representation of the button. Scripts are always run last in the request/response cycle. There is also a web method callback system from JavaScript – call the server from the client marking an *instance* method [WebMethod] – and Wisej builds an entire object model on the client side under window.App. But this is a topic for the documentation and an example.
  • Ngabo Adrian
    Hello Luca, Thank you for your support. Can the Sample that you talked about up on this issue be available once again? I’ve tried to download it but it seems its not there! Can you provide it for us again? Thank you Adrian
  • Frank (ITG)
    Ngabo, please check out our sample here: https://github.com/iceteagroup/wisej-examples/tree/3.0/KeyboardHandling Best regards, Frank
  • Ngabo Adrian
    Its alright, Thank you very much. I’ve seen it. Let me go through it. Adrian
  • You must to post comments

Thanks Takashi,

we have logged this bug in our tracking system as WJ-7225.
We will post a new answer here when it is resolved.

  • You must to post comments
Showing 2 results