Get-UDElement is not working

I am getting null all the time for Get-UDElement. Not sure what i am doing wrong.
i am using version 2.9.0

$HomePage = New-UDPage -Name “Home” -Icon home -Content {
New-UDTextbox -Id ‘message’ -Placeholder “Enter the some text”
New-UDButton -Id “btnSearch” -Text “Click me!” -OnClick {
$txtMessage = Get-UDElement -Id ‘message’
if ($txtMessage -eq null){Show-UDToast -Message "Component is null"} #Show-UDToast -Message ($txtMessage.Attributes[‘value’])

Get-UDDashboard | Stop-UDDashboard
Start-UDDashboard -Port 2000 -Content {
New-UDDashboard -Title “Welcome” -Pages @($HomePage)

Hi @premgoks, welcome.
See if this works for you.

$HomePage = New-UDPage -Name "Home" -Icon Home -Content {
    New-UDTextbox -Id 'message' -Placeholder "Enter some text"
    New-UDButton -Id 'btnSearch' -Text "Click Me!" -OnClick (
        New-UDEndpoint -Endpoint {
            $txtMessage = (Get-UDElement -Id 'message').attributes.value
            If($txtMessage -eq $null) {
               Show-UDToast -Message "Component is null"
            } else {
                Show-UDToast -Message $txtMessage

Main things I changed, the -OnClick parameter, I put a New-UDEndpoint inside that, which let’s you run script logic. I’d recommend this article by @psDevUK, for some better info on endpoints (
Set the $txtMessage variable to be the value of the Get-UDElement, since even if the field is empty or null, Get-UDelement will return a powershell object, so it technically will always have something in it.
Hope that helps.

Hi @RamonMA,
Thanks for your response, i tried your code, but still i am getting "Component is null " :frowning:

I think the “onclick” event is an endpoint in it’s own right as it runs the code inside the script block each time you click the button so I’m not sure if you need an endpoint within it.

Does this do what you’re looking for?

$HomePage = New-UDPage -Name "Home" -Icon home -Content {
    New-UDTextbox -Id "message" -Placeholder "Enter the some text"
    New-UDButton -Id "btnSearch" -Text "Click me!" -OnClick {
        $txtMessage=(Get-UDElement -Id "message").Attributes['value']
        if ([string]::IsNullOrEmpty($txtMessage)) {
            Show-UDToast -Message "Component is null"
        else {
            Show-UDToast -Message ($txtMessage)
Get-UDDashboard | Stop-UDDashboard
Start-UDDashboard -Port 2000 -Content {
New-UDDashboard -Title “Welcome” -Pages @($HomePage)

Hi Tom,

Thank you for your time.
But still its not working . Thing is 'Get-UDElement -Id “message” ’ is always returning null.

Hm that is odd! have you tried re-installing the UD module? If I use the same code I get this:

Struggling with the same issue. However I find the issue intermittent, meaning I have two buttons leveraging -OnClick to set the value of a variable from the same Get-UDElement target. One of the buttons works, the other dosent… I have been poking at this with sharp sticks for quite a while but the struggle is real when the output is either null or as expected… sometimes for both, none, or only one of the buttons?!

New-UDButton -Text "Enable Maint Mode" -OnClick {
                $EMMButton = Get-UDElement -Id 'DRAssetMMStatusTable'
                $EMMButton | convertto-json | out-file -path E:\PSHome\PSOutput\DRToolbox\EMMButton.json 
              New-UDButton -Text "Disable Maint Mode" -OnClick {
                $DMMButton = Get-UDElement -Id 'DRAssetMMStatusTable'
                Show-UDToast -Message "$($DMMButton|out-string)"
                $DMMButton | convertto-json | out-file -path E:\PSHome\PSOutput\DRToolbox\DMMButton.json 

That’s annoying. Sorry about that. We have a recent thread going on about this.

I had some debugging information sent my way and am investigating.

I’ve actually wrapped my table with New-UDDynamic, which seems to have helped out a lot! As of right now I have not seen the intermittence issue crop back up but will post again if I do.
-Do appreciate the follow up though and details regarding the additional thread!