HtmlBox CodeSample - Invoking JavaScript method inside the Html of a HtmlBox

From Visual WebGui Wiki

Jump to: navigation, search


Overview

Having an HtmlBox that contains some Html that defines a JavaScript method, it is not uncommon that you will need to invoke that JavaScript from within the Visual WebGui application. This codesample will demonstrate how you can invoke such a JavaScript function (call it MyJSMethod).

Please note that the HtmlBox has an IsWindowLess which decides if the HtmlBox will be rendered within an Html IFRAME or not. The default is IsWindowLess = False, and the code below is only meant to work for this scenario.

VB.NET code

' Assume code is run from the form containing the HtmlBox
Me.InvokeScript(String.Format("document.getElementById('TRG_{0}').contentWindow.EvalSound();", Me.HtmlBox1.ID))

C# Code

// Assume code is run from the form containing the HtmlBox
this.InvokeScript(string.Format("document.getElementById('TRG_{0}').contentWindow.EvalSound();", this.htmlBox1.ID));
Personal tools