JavaScript
Last updated
Last updated
Wisej.NET enables adding unlimited JavaScript code with direct widget references. Your JavaScript code can be in .js
files, called from C#/VB.NET, or embedded in resource files.
All controls written in C#/VB.NET on the server are created as pure JavaScript widgets on the client and registered in a new object model under App
. See JavaScript Object Model.
You can add JavaScript to a Wisej.NET application in several ways:
Script tag in Default.htm
You can add scripts in the application startup page (usually Default.htm
). However, scripts in the <head>
tag execute before the Wisej.NET library loads and initializes. Even scripts loaded on document ready are too early for application widgets. Therefore, JavaScript in Default.htm
should only be used for non-Wisej.NET purposes.
Embedded resource
Create a .js
file, set it to EmbeddedResource under /Resources
or /Platform
and add [assembly:WisejResources]
to AssemblyInfo.cs
. Wisej.NET loads and invokes these JavaScript files in order with the framework library.
While too early for application objects, this is ideal for installing additional widget classes or overriding existing ones. All Wisej.NET widgets use this technique.
JavaScript Extender Provider
Drop the JavaScript Extender
on any top-level container (Form
, Page
, Desktop
or User Control) to extend all controls with two properties: JavaScript
and JavaScriptSource
.
The JavaScript
property accepts JavaScript code that runs in the control's context - this
refers to the control's widget on the client. You can use widget methods, properties and address related widgets. This code runs last, after Wisej.NET renders and updates page widgets.
Use this extender to attach client events or modify widget behavior. The image below shows a button code snippet displaying a client-side alert:
The JavaScriptSource
property works similarly but accepts a .js
file instead of inline code. This is useful for longer scripts and leverages Visual Studio's JavaScript editor.
Note that Call
method's first parameter is just the function name, while Eval
expects a complete script: