Links

Widget

Wisej.Web.Widget
Namespace: Wisej.Web
Assembly: Wisej.Framework (3.1.0.0)
Provides a generic widget that can use most third party javascript widgets.
C#
VB.NET
public class Widget : Control, IWisejHandler
Public Class Widget
Inherits Control
Implements IWisejHandler
See the InitScript property for a detailed description on how to initialize the imported widget.

Constructors

Widget()

Initializes a new instance of the Widget class.

Properties

BorderStyle

BorderStyle: Indicates the border style for the control.

EnableNativeContextMenu

Boolean: Enables or disables the browser's context menu.

InitScript

String: Returns or sets the initialization script.
The initialization script is called after the widget is created and before it is rendered by the browser. It is here that the code should initialize the third party widget, hook up any event, and save any reference it may need. The initialization function is named "init" and must be declared like this:
this.init = function(options)
{
// simple example on how to initialize
// a jQuery hypothetical widget.
$(this.container).widget(options);
// alternative example on how to
// initialize a widget that needs a specific
// child element.
this.container.innerHTML = "<select id='widget'></select>
$('#widget').widget(options);
}
The update function is named "update", it is optional, and must be declared like this:
this.update = function(options, old)
{
// update the widget either using the
// changed options or by invoking specific methods.
$('#widget').widget(options);
}
The "options" parameter is optional. It contains a javascript map with all the options defined in the Options property. Within the init function you can refer to the Wisej widget class using "this" and to the HTML element using "this.container". To fire an event back to the server, use "this.fireWidgetEvent() as show in the sample code below:
this.init = function(options)
{
// add the onSelect handler to the initialization options
// to relay the client event back to the server side
// representation of the widget.
//
// The e.getId() and e.getText() are just examples, the values
// to send back to the server depend on the third party widget
// and the event specification.
var me = this;
options.onSelect = function(e) {
me.fireWidgetEvent("select", {id:e.getId(), text:e.getText()});
};
$(this.container).widget(options);
}
On the server side, you can handle the WidgetEvent and receive any data passed in the "fireWidgetEvent" call in the Data dynamic object.

Instance

Object: Returns a DynamicObject that can convert any method call into the equivalent JavaScript call targeting the third party "widget" object.
An application can invoke any method on the wrapped third party widget by using the Instance property. Dynamic method calls are automatically transformed to JavaScript client calls.
// invokes the setLineColor(color) JavaScript method
// on the third party chart widget.
this.chart1.Instance.setLineColor("red");
// to get a return value you can add either a callback function or
// use the Async version and await the result.
this.chart1.Instance.getSeriesCount((count) => { AlertBox.Show(count.ToString()); });
// all methods have the Async version registered automatically.
var count = await this.chart1.Instance.getSeriesCountAsync();
AlertBox.Show(count.ToString());

IsLoaded

Boolean: Returns whether the JavaScript widget has been initialized.

Options

Object: Returns or sets a dynamic object that is passed to the init(options) function upon initialization of the widget and to the update(options, old) when updating the widget.
The Widget class automatically detects changes to first level fields only. If your code changes a nested object you have to either call Update or notify the Options object that a property has changed like this:
this.widget.Options.value = 10;
// no need to notify, value is a first level field.
this.widget.Options.toolbar.show = true;
// need to notify, show is a field of toolbar.
this.widget.Update();
// or
this.widget.Options.Notify("toolbar.show");
this.widget.Options.toolbar = new { show = true };
// no need to notify, we are setting toolbar.show but the assignment
// changes toolbar which is a first level field.

Packages

List<Package>: List of packages required to run this widget.
Each package is a URL to either a JavaScript or a CSS file. The packages are loaded in the order they are listed. If a script depends on another script, it should be declared after the script it depends on, i.e.: Query usually if the first script in the package list. Wisej uses the name of the package to cache it and load it only once. It's important that you use consistent names when creating multiple widgets in order to load the shared packages only once.

WiredEvents

String[]: Returns or sets the list of events that are fired by the widget wrapper.
Defines the list of events that the widget wrapper can fire. You have to add the code that handles the third party widget's events and fire a server event back to this widget wrapper. If your initialization code fires the event correctly and the event is registered in the WiredEvents list, the application code can attach a listener to the dynamic Instance object like any native event.
this.chart1.WiredEvents = new [] {"AreaClick"};
this.chart1.Instance.areaClick += new WidgetEventHandler(chart1_AreaClick);
private void chart1_AreaClick(object sender, WidgetEventArgs e) {
// event data is available at e.Data as a dynamic object.
var data = e.Data;
var x = data.x;
var y = data.y;
var name = data.name;
AlertBox.Show($"Clicked area {name} at {x}, {y}.");
}
For the sample code above to receive the "areaClick" event you have to handle the third party widget event and fire a Wisej event. The syntax for the handler registration depends on each wrapped third party widget: some may use native events, other may use jQuery, and others may use callback methods.
var me = this;
this.widget.addEventHandler("areaClick", function(e){
me.fireWidgetEvent("AreaClick", {name:a.areaName, x:e.xPos, y:e.yPos});
});
The list of the wired events that the server component expects to receive is available on the client side wrapper using the events array: this.getEvents(). [Since 2.5.31] You can attach to the event without having to register it with the WiredEvents collection when you prefix the handler with "on". i.e. this.Instance.onPointClick += new WidgetEventHandler(onPointClick). Wisej will try to attach to the "pointClick" event automatically removing the "on" prefix. When you attach the listener Wisej will automatically add it to the WiredEvents collection. Additionally, instead of having to iterate the this.getEvents() collection in the widget's initScript, you can override "_addListener", "_removeListener", "_getEventData".
this._addListener = function(name, handler) {
this.widget.on(name, handler);
}
this._removeListener = function(name, handler) {
this.widget.off(name, handler);
}
this._getEventData = function(type, e, expression) {
if (type === "cellClick") {
return {row:e.rowIndex, column:e.colIndex};
}
}

Methods

AddListener(eventName, handler, expression)

Registers the event handler to listen to the event eventName fired by the third party widget.
Parameter
Type
Description
eventName
String
Name of the event fired by the third party widget.
handler
Function that handles the event on the server side.
expression
String
Optional expression to process the event data: i.e. "{x:e.x, y:x.y}".
Using AddListener only registers the server side handlers and adds the eventName to the list of WiredEvents. However, the client side wiring of the client event and the firing of the event back to the server must Throws:

RemoveListener(eventName, handler)

Removes the event handler for the eventName fired by the third party widget.
Parameter
Type
Description
eventName
String
Name of the event fired by the third party widget.
handler
Function that handles the event on the server side.
Throws:

Events

Load

EventHandler Fired when the widget is created on the client.

WebRequest

WebRequestHandler Fired when the widget used the "postbackUrl" to retrieve data from this control.

Implements

Name
Description
Bindable components implement this interface.
All wisej components implement this interface.
All wisej controls derived from the Control class must implement this interface.
Represents a Wisej component that is capable of handling postback requests from the client.
Allows an object to serialize itself.