Hi Joe,
Calling JavaScript functions is very much dependent on scope. If you are reacting to events within the AspPageBox's loaded resources, calling event handlers within that page's code, the scope is the currently loaded resource, in this case your loaded aspx page.
Calling the global Visual WebGui methods, you still need scoping to be able to call them. If you are calling from server-side via some of the InvokeMethod methods, like on a form, you call this.InvokeMethodWithId("somemethod"), that JavaScript call is issued within the scope of the Form etc. etc.
For convenience in Visual WebGUi, the JavaScript loaded on each form declared a JavaScript variable, mobjApp, that is a reference to the global resources scope, and through it you can call any of the global resource JavaScript functions, like mobjApp.Web_GetWebId().
When you load an aspx resource within an AspPageBox, that resource is responsible for it's own environment, and there you don't have access to the global resource's mobjApp variable. To get to it, you can write a simple JavaScript function that looks something like this:
function AspPageBox { "You've got me"); }
// Get reference to parent's mobjApp for current window
function GetVGWmobjApp()
{
var objCurrentWindow = window;
var mobjApp = null;
while (!mobjApp && objCurrentWindow)
{
if (objCurrentWindow.mobjApp)
{
mobjApp = objCurrentWindow.mobjApp;
}
else
{
objCurrentWindow = objCurrentWindow.parent;
}
}
return mobjApp;
}
This will return you an mobjApp variable, through which you can reach the global resources.
Calling a JavaScript method that is located within your AspPageBox's loaded resource, you need to locate the node that holds the loaded resource's document object, and there you have access to it's DOM.
Let's say you have a simple aspx page, on which you declare just a single javascript function in the header, say:
function AspPageBox { a lert("You've got me"); }
If you then add a Form with a Button and an AspPageBox, that loads this aspx form, you could on Button.Click run the following (note that I use mobjApp, as the call is coming on your Form's scope, which already has it wired up):
this.InvokeMethod("mobjApp.InvokeAspMethod", this.aspPageBox1.ID.ToString());
Where this JavaScript InvokeAspMethod function would be declared as:
function InvokeAspMethod(strControlId) {
var mobjApp = GetVGWmobjApp();
// the VWG control - the AspPageBox
var mobjVWGNode = mobjApp.Web_GetWebElement(mobjApp.Web_GetWebId(strControlId), mobjApp);
// the document that contains the resource (your aspx elements)
var mobjVWGDocument = mobjApp.Web_GetTargetElementByDataId(strControlId, mobjApp).contentWindow;
// Invoke your own JavaScript function within the loaded resources of the AspPageBox.
mobjVWGDocument.AspPageBox
}
What it does, is first to establish a reference to Visual WebGui's global resources. Then it uses those to find the AspPageBox itself (mobjVWGNode), which is not necessary in this case, but I threw it in for explanation purposes. Then it locates the TargetElement, which in it's contentWindow has your loaded AspPageBox's document, and you can call your alert function directly on that node.
In order to use those two JavaScript functions above, they need to be accessible within the scope you are calling, so they are probably best added to your custom control as JavaScript resource, with the proper naming convention of YourControl_FunctionName etc.
Hope this explains and helps some,
Palli