Set-UDElement only works in buttons

Product: PowerShell Universal
Version: 4.1.4

Hello everybody!
I’m having some issues with Set-UDElement :frowning:

I have a class with a method called SetContent that updates the content attribute of the class as well as the content displayed in a text box:

[void] SetContent ([string] $Content) {
	$this.Content = $Content
	Set-UDElement -Id $this.GetID() -Properties @{ Value = $this.Content }
}

However, when I call the method like this:

$SearchByName.SetIcon("skull-crossbones") # Other code
$SearchByName.SetContent("Hello :)") # <--- Here
$SearchByName.GetID() # Other code

the Set-UDElement doesn’t work. The content attribute is updated just fine, but the value inside the textbox doesn’r change.
I tried using a button to update the value shown:

New-UDButton -OnClick {
	$SearchByName.SetContent((Get-Date -Format "o"))
}

And it worked just fine.

The textbox looks like this:

New-UDTextbox -Id $SearchByName.GetID() -Label $SearchByName.GetName() -Icon (New-UDIcon -Icon $SearchByName.GetIcon()) -HelperText $SearchByName.GetHelper() -OnChange {
    $SearchByName.SetContent($EventData);
} -FullWidth

Am I doing something wrong? I don’t understand why it’s not working :confused:

(Also the SetIcon() method works just fine, even without a button)

It seems the element isn’t actually created until the page is loaded. Since the code outside the button executes itself before the load is complete that would explain why it doesn’t work even if the button works. I just have to figure out how to delay the code execution until the page load is complete. At least that’s what I think