Events

Event routing concepts.

Event routing is a cornerstone of the Wisej.NET architecture. Wisej.NET client-side JavaScript widgets can fire events on the server and server-side components can fire and handle events synchronously or asynchronously (out-of-bound) using the .NET standard events system.

Event Handling

Handling events is as simple as attaching a listener to the event of overriding the equivalent OnEvent method. There is really nothing else to it.

this.button1.Click += this.Button1_Click;
...

void Button1_Click(object sender, EventArgs e) {

  this.button1.Text = "Clicked!";

}

Another way to handle events in derived classes is to simply override the OnEvent methods and process the event before or after it's fired.

class MyButton : Wisej.Web.Button {

protected override void OnMouseDown(MouseEventArgs e) {

  base.OnMouseDown(e);
  
  this.Text = "The mouse is at " + e.Location;

}

Role Attribute

All pointer events on all components carry the Role property. This property contains the value of the "role" attribute of the specific HTML element that was clicked by the user.

In most cases it is just an empty string. However, you can use this feature to "deep click" inside a component and detect where the user clicked. For example, if you place HTML content in a DataGridViewCell like this:

"<span>Hello</span><img src="edit.png" role="edit"/>"

You can handle the CellClick event (or any other cell pointer event) and check whether the value of the e.Role property is "edit". This works for labels, buttons, ListView, and any component in Wisej.NET that can display HTML content.

Lazy Events

There is a group of "critical" events that are not fired back to the server unless the application has specifically attached to the handler. These are events that would typically fire multiple times.

  • MouseMove

  • MouseEnter

  • MouseHover

  • MouseLeave

  • MouseWheel

  • KeyDown

  • KeyPress

  • KeyUp

  • QueryContinueDrag

  • DragDrop

  • DragEnter

  • DragOver

  • DragLeave

  • Swipe

  • Paint

  • Pinch

  • Rotate

  • Track

  • TouchStart

  • TouchEnd

  • TouchCancel

  • Scroll

  • ModifiedChanged

  • LoadCompleted

  • ItemMouseHover

  • CellMouseEnter

  • CellMouseLeave

  • CellMouseMove

Once a handler is attached, you may also override the OnEvent method in a derived class.

Touch Events

Out-of-Bound Events

Out-of-bound events are events fired outside of a browser request (user action). For example, an event fired by a thread monitoring the stock market is an out-of-bound event since the thread is running in the background and is unaware of any browser activity.

The client may also fire unattended events back to the server. However, these are in-bound events since the server is processing a request from the browser and has a valid session to work with.

When processing out-of-bound events you are processing a background task, which is a thread that has absolutely no knowledge of the session that is handling the event. Handling out-of-bound events - something close to impossible with other systems - is easy with Wisej, all you need to do is wrap the handling code in Application.RunInContext(component, ()=>{ code }) or Application.Update(component, ()=>{ code }).

The only difference between RunInContext and Update is that the Update call pushes any changes to the visual components back to the client.

Once you are back in context, you can handle any component in the user session: update text, hide, show, move. There are no limits to what you can do using Wisej.NET Real-Time features.

JavaScript Events

When creating new Wisej.NET components and widgets, or integrating existing jQuery or other third-party JavaScript widgets, you will most likely need to fire an event from JavaScript running in the browser back to the server and handle it as any other .NET event.

This is how you fire the event from a Wisej.NET widget:

The example above shows how to fire JavaScript events back to the server.

The example below shows how to register a Wisej.NET control to receive custom events and how to handle the data transported with the event.

When integrating third-party widgets, you can handle and process their events in JavaScript and send back to Wisej.NET a custom event of any type. All you need to do is to handle their events as indicated in the third-party widget's documentation and then fire it to Wisej.

Last updated

Was this helpful?