New-UDButton not keeping state between sessions

Version 2.9.0

I’m trying to keep the state of a button when a user (or multiple users) refreshes their web browsers. Unfortunately the button is being ‘reset’ on every refresh of the browser. Is there a -OnRefresh event I can capture to read the state of the button from a text file? Or is there a better way to keep the state?

Import-Module UniversalDashboard.UDButtonLoader
Get-UDDashboard | Stop-UDDashboard
Start-UDDashboard -Port 1000 -FORCE -Dashboard (
    New-UDDashboard -Title "Powershell UniversalDashboard" -Content {

        New-UDButton -Id "Loading" -Text "Test" -onClick {

            function Set-UDButtonStateChange {
                param($Id, $Text, $Color, [Switch]$Disabled)
                if ($Disabled) {
                    Invoke-UDJavaScript -Javascript "
                    document.getElementById('$($Id)').disabled = true;
                    document.getElementById('$($Id)').textContent = '$($Text)'"
                } else {
                    Invoke-UDJavaScript -Javascript "
                    document.getElementById('$($Id)').disabled = false;
                    var btn = document.getElementById('$($Id)');
                    btn.textContent = '$($Text)';
                    btn.style.backgroundColor = '$($Color)'"
                }
            }

            Set-UDButtonStateChange -Id 'Loading' -Text 'Change Text'
        }
    }
)

Hi @Zuldan and welcome to the UD forums! As far as I understand refreshing the browser page will clear the session variable. I did publish a couple of loading buttons on the marketplace here:-
https://marketplace.universaldashboard.io/Dashboard/UniversalDashboard.UDButtonLoader
demo here:- New dynamic button for universal dashboard

and here:-
https://marketplace.universaldashboard.io/Dashboard/UniversalDashboard.UDButtonParticle
demo here:- https://github.com/psDevUK/UD-ButtonParticle/blob/master/DEMO.ps1

From your code you kindly shared I just see you in essence want some sort of loading button?

Hi psDevUK, thank you for the response . I already use your buttons in a different section of the Dashboard, they are great, thank you.

I’m trying to link the state of physical devices (ON/OFF) with the state of a button (it’s colour). So I needed the buttons to sync to the physical devices on a page refresh. I managed to resolve the issue by wrapping the buttons in a New-UDElement -AutoRefresh.

The problem I have now is if I have the dashboard open on 3 different computers the button only changes it’s colour on the computer I clicked the button on. I used the Sync-UDElement -Boardcast (making sure I used the correct button ID) but none of the other computers have the updated button colour.

Any ideas?

if you want it to reflect on all computers…I believe you need to use the broadcast parameter…have a search on the forum for broadcast I believe that will do the trick fella.