How to keep a button disabled after user clicks away?

Product: PowerShell Universal
Version: 3.6.2

I can easily disable a button onclick with

Set-UDElement -Id 'button' -Attributes @{Disabled = $true }
Sync-UDElement -Id 'button'

However, if the user clicks away from that page and then back, the button is able to be clicked again.
Even if I add the same code to the very top of the page the user can click the button again. How can I persist the disabled state of the button?

Thanks!
Kevin

If the idea is to keep it disabled for the user’s session then you’ll want to assign a $Session: variable.

#When you are creating the button..
If ($Session:ButtonDisable -ne $true) {
    New-UDButton -id 'button'
} else {
    New-UDButton -id 'button' -disabled
}
#Rest of the code
Set-UDElement -Id 'button' -Attributes @{Disabled = $true }
$Session:ButtonDisable = $true
Sync-UDElement -Id 'button'
#Rest of the code

Thanks for your reply. I actually don’t even have a condition. Just to disable at the top of the page. I believe the challenge is that my button is not all the way at the top it does succeed at disabling it on click.

@Jori as a test, this is what I used and it does not disable when the user clicks back to this page… (perhaps there is a way relocate the button on the ps1 file?)

You’ll need to conditionally create the button, as I posted before. If you need help, post the code with any sensitive info removed, I can show you what I mean.

1 Like

You were 100% correct. Thank you.

I just built a function and called it with a switch parameter (and without) like your example. Thanks so much!
Kevin