again: Error: Could not execute returned javascript: undefined is not an object

Hi Everybody,

I need to ask Your help…

I’m getting the following error while adding controls with EmbedWithin.

Error: Could not execute returned javascript: undefined is not an object

I’ve already checked all around, but I’m not able to find a solution, since it seems different from other situations.

The error is NOT raising every time, and not on every container I’m adding.

this is part of the JAVA error log (not related to the below images, but to show one of the errors):

2020-02-11 11:31:40
JavaScript Error:
Error: Could not execute returned javascript: undefined is not an object (evaluating ‘Xojo.controls[‘oHBwysgK’].setAttribute’)
Source: new webcanvas(‘bxuXz6OY’,

just a short part of how I’m working with the code, but, as mentioned, even running in debug mode, nothing is going into exception.
Riga(tot_righe) = New ContainerQty
Riga(tot_righe).EmbedWithin(Self, oOffset, mOffset, Riga(tot_righe) .Width, Riga(tot_righe) .Height)

What i saw through WEB INSPECTOR is that it seems the Object is created two times, one correctly and one without all the classes, but with the same instance name as far as I can understand

This the example of duplicate “Sg0xjRiQ” :

and this how it shows on the web pace:

Thanks a lot for any suggestion.


I suggest making the control into a local variable, embedding it and then putting it into the array.

Usually what this error means is that the instructions for configuring the control are arriving before the instructions for creating the control, instead of after.

FWIW, we’ve eliminated most of these types of errors in the new web framework. Come to Xojo.Connect In Nashville to get some hands-on time to play with it!</Xojo Promo>

Thanks Greg,
I’ve tried to make it local variable, added all information and than transfer it to the array before embedding.

TEMP = New ContainerQty
TEMP.Lab_Size.text = taglia
TEMP.Lab_add_size.text = taglia_desc
TEMP.Lab_Price.text = prezzo.ToText + " €"

Riga(tot_righe) = TEMP
Riga(tot_righe).EmbedWithin(Self, oOffset, mOffset, Riga(tot_righe) .Width, Riga(tot_righe) .Height)

This was what You were saying, correct?

Now something is changed.

The container is replicated two times, with the correct datas in both.

both with the same ID: SeuGS1tQ

Is like the Embedd function is fired two time, bust still has not the Style=“visibility: visible”

first is the correct one and has in Style Visibility : visible
the second is the fake and for example has no Visibility set.

I don’t know if for same reasons the system is considering two instead of one due to this, but with the same ID is going to raise an error. Anycase it should be one.

Thanks for Your help!


Hello Greg,
I’ve tried also to add to the Array after

TEMP.EmbedWithin(Self, oOffset, mOffset, TEMP.Width, TEMP.Height)
Riga(tot_righe) = TEMP

the result is quite the same. The different is that on of the two the row is showing empty.
In all cases, the two rows are not on the same position, even the setting should be he same sent in the embed command.
(oOffset and mOffset).

It seems EmbedWithin command is called one time, but is adding two time the container.

Any other suggestion to try?

Nice day!

Hi Enrico,
from your code I see that you are setting properties of controls before the embedwithin().
Try to set or modify controls properties only after the container you are embedding has fired the shown() event.
Yes, it requires to change a little your code but this can solve the problem.


Thanks Maurizio,
I will try this option too and give You feedback about result. :slight_smile:

Nice day!

Hello Maurizio and Greg,

really thanks for your support.

Maurizio: I’ve tried in an easy way, just embedding the control without touching any properties. Unfortunately the same result.
So I was more confident it was something in the code around at this point.

I’ve made several trials and this what i realised and would like to check with You:

Before calling the Control.AddControl method I was calling the Control.Clear method to close all the embedded controls if already existing. (Since the control is changing according User activity).
I’ve commented the call to this method (and of course adapted the Addcontrol method to check if the embed control already exist) and now it seems no error is coming out.

while (ART.Dati_Articolo_Dettaglio_Quantita.EOF <> true)


That could result in Control.Clear was some time not totally finishing before the sequential call to Control.AddControl Method?
What do You think? Could be this the reason?

Of course now I will have to change a bit the code to obtain the same result without calling the control.Clear directly.

Nice weekend,

Hi Enrico,
I must admit that I don’t understand what your code is supposed to do.
Maybe this can be caused by the terms you are using: control instead of container, I don’t know.
I’m shooting in the dark so what follows could be totally wrong.
I suppose you are embedding a container for each record pulled from a database and this is done with the AddControl() method.
The Container_Quantity.Clear() method is possibly used to remove any previously embedded container.
If this is the case you must be sure that:

  • for any previously embedded container you are removing, the Close() method of the container itself is called
  • any new container you add is created using operator new and embedded with the EmbedWithin() method
    At this point the question is: how do you keep track and references of the containers?
    If you are using a variable defined as an array of webcontainer you must be sure that you empties the array in the Clear() method and the newly created containers will be added to the same array.
    Please remember that you are creating entities on a remote place i.e. the browser and the methods you are calling are simply creating a queue of commands that will be sent to the browser when your methods terminates.
    So for each embedded container you must wait for the Shown() event that informs you that the container was created on the browser and from this point is ready to accept commands to change properties for the elements in the container itself.
    The container Close() method delete the container in the browser but not from your program.
    Nulling the variable that refers the container in you code remove the container from your program.
    Nulling the variable is removing an element from the webcontainer array or simply replacing its content with a new container reference.

Hope this can help.
Sorry if I misunderstood your code and intents.
Best regards.

1 Like

Hello Maurizio,

my apologises, You’re right. Is CONTAINER the correct word.
What You say is matching perfectly what I need to do.

The difference was that in my previous code, Container_quantity.Clear was passing the array containing the valids references and closing them with Close() method when a Container was not Nil.
Could be this was executed sometime in parallel with the new Container_quantity.Add method raising the error.

Now I’m doing a check, if the container is already there, I just change the properties, add more embedded Containers in case I need them.
I’m closing totally through the total array just when I need to change completely.

Actually it works. Maybe still not totally correct… :slight_smile:

Thanks and my apologies for not good explanation.
I’m really new for WEB programming and just few months on XOJO in general.
Before i was programming through C++ so I’m learning day by day!