web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Button goes back to de...
Power Apps
Answered

Button goes back to default color after refresh

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Button 1 is pressed so it changes the color from blue to yellow and it should stay yellow even if the browser get refreshed. 

But right now if the browser get refreshed the app starts from scratch.!!

 

Any idea's?

Capture.PNG
Categories:
  • RusselThomas Profile Picture
    4,014 on at

    Hi @Anonymous ,

    The entire app will restart if the browser is refreshed, and all components will be reset to their default state, so this is unavoidable unless you save the state of the button outside the app - for example in a sharepoint list somewhere - and then load the state when the app starts.

    Kind regards,

    RT

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hello @RusselThomas 

    Thanks for the respons dear.

    let me just say that i am very new to powerapps. 

    I have a sharepoint list and its connected to the app, i just dont know how to record the button status to a column. 

  • Verified answer
    RusselThomas Profile Picture
    4,014 on at

    Hi @Anonymous ,

    We are all learning every day 🙂

    Just a caution - this might be a bit tedious depending on how many buttons you want to do this for.  If you can't avoid people refreshing the entire browser then keep reading...

     

    You can create a list in your site and call it ButtonStatesList or something.  

    Add columns to identify the button and its state - you can use the default Title column for the button and add a single-line-of-text column called "State". 

    Back in your PowerApp, add a datasource by clicking on the data icon on the left of the screen and Add Data - find Sharepoint and add a Sharepoint data source.  Then on the right find and select your site and select your ButtonStatesList.  

    With your list connected to your app, add a button and change it's name to "Button1" - you can do this by selecting the button and then either on the right where you see it's name above the properties you can edit the name, or if you're using the Tree View on the left just double-click the button in the tree view and you can rename it.  You can call it whatever you want, it won't change anything other than your ability to easily identify it while looking at your app - what's important is what the buttons saves to SharePoint in the Title column that will associate it with it's own state.

    Set the OnSelect: property of your button to;

     

     

    With({buttonRecord: LookUp(ButtonStatesList, Title="Button1")}, 
    //gets the existing button record, if it exists and places it into a variable called "buttonrecord" that we can reuse later in our formula
    
    If(IsBlank(buttonRecord.State), 
    //checks if there's an existing record by checking if the state is blank - i.e. nothing has been captured yet
    
     Patch(ButtonStatesList, Defaults(ButtonStatesList), {Title: "Button1", State: "On"}), 
     //if it is blank, then we assume there's no record yet and create one the first time the button is pressed, and set it's state to "On"
    
     Patch(ButtonStatesList, buttonRecord, {Title: "Button1", State: If(buttonRecord.State="Off", "On", "Off")}) 
    //if it's not blank, then the record already exists so we update the existing record, setting it to "On" if it's currently "Off" and "Off" if it's currently "On"
    
    )
    
    )

     

     

     Now go to your button Fill: property and set it as follows;

     

     

    If(LookUp(ButtonStatesList, Title="Button1", State)="On", Yellow, Blue)

     

     

    That should do it.  If you add more buttons, just make sure each button is set to check for whatever Title it's capturing when pressed - Just replace the above with "Button2", "Button3" etc. as you go.  Whenever your app is loaded, the button will get it's Fill color from the list.

    You should note this will work fine for one person using the app - PowerApps will refresh the state automatically whenever it's updated by that user for that PowerApps session - but nobody else will see the update unless their app is continuously checking for it, or they update the color themselves and force a refresh for their session.  If you want everyone to see state updates whenever someone else updates them, you'll have to add a timer to Refresh() the data source periodically.  To do this, just add a time control and set the following properties;

    • Duration: 15000 (refreshes every 15 seconds)
    • Repeat: On/true
    • AutoStart: On/true
    • OnTimerEnd: Refresh(ButtonStatesList)
    • Visible: false
    • AutoPause: On/true if your buttons only exist on one screen, Off/false if they are spread across multiple screens

    You Hope this helps 🙂

    RT

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @RusselThomas 

     

    You did it, thank you dear 👍

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

     

    Hello @RusselThomas 

    Could you help me again please? 

    I have these 3 buttons that changes 7 different colors one color pr. click. i want to patch button values to my sharepoint list so when i restart the app the buttons stays at same color and dont go back to default. Just the same like the first problem but now the buttons changes between 7 colors. 

     

     

     

     

     

     

    The code is for each button: 

    On.Select

    If(gblClickCount<7;Set(gblClickCount;gblClickCount+1);Set(gblClickCount;1));;

     

     

     Fill.
    Switch(gblClickCount;
     
    1; Green;
     
    2; Yellow;
     
    3; SkyBlue; 
     
    4; Orange;
     
    5; MediumPurple;
     
    6; Red;
     
    Capture1.PNG
  • RusselThomas Profile Picture
    4,014 on at

    Hi @Anonymous ,

    So at this point, the user experience becomes a critical deciding factor in how you take it forward.

    Do you want each user to keep track of their own button clicks, or are the button states universal (the same) for all users?  i.e. if I click button 3 through to Orange and you're running the app, do you want to see button 3 change to Orange?  Or do you want to track your own button clicks independent from mine?

    Kind regards,

    RT

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @RusselThomas 

    Thank you for your respons.

    All users should be the same there is only one display for this app. I just dont want to lose any data when the app gets refreshed in the web browser . 

     

    Best regards 

     

     

  • RusselThomas Profile Picture
    4,014 on at

    Hi @Anonymous ,

    That makes it easier, as you're already saving a row of data for each button 'state'.

    All you need to do is add a number column to your button state list - call it 'buttonClicks' or something that makes sense to you - this is where you can store the number of clicks the button is on.  Remember to refresh the data source in PowerApps after you've added the column to SharePoint ("Data" menu, "..." next to your data source, "Refresh")

    If we take a step back and look at the solution, it may make more sense to keep your number/colour reference as a lookup table than just existing in logic.  By this I mean, instead of switching the value of ClickCount for each button to get the fill colour, it would be better to store the clickcount/fillcolour in a table and just look it up.

    This way, if you want to change the colour of a number, you don't have to go and edit three buttons worth of code to do it.

    There is a behaviour called App Start you can use to initialise information for your app.  This will run exactly once, when your app starts.  You can put any behaviour functions in app start, including collecting data from a source, setting variables, or in this case, creating a reference table for your app to use.

    On your left navigation menu, above your first screen (usually Screen1), you should see "App". Click on this, and then make sure your formula bar property is set to OnStart (the down arrow to the left of the fx on the formula bar).

    This can go in your OnStart: property;

     

    ClearCollect(collectClickColours; {
     numClicks: 1; fillColour: Green;
     numClicks: 2; fillColour: Yellow;
     numClicks: 3; fillColour: SkyBlue;
     .....
     });;

     

    So here we'll set up our collection called collectClickColours with a column "numClicks" and corresponding "fillColour" (you can call the columns what you like, as long as it makes sense to you - just replace the ..... with the rest of the numbers and colours - I'm lazy 🙂)

    Our buttons will reference this table to get their colours - and if we want to change a numbers colour, we only have to do it here, once.

     

    Now your buttons' Fill: properties can look as follows;

     

    LookUp(collectClickColours;
     numClicks = LookUp('buttonStatesList'; Title='Button1'; clickCount); fillColour
    )

     

     If there's only one screen/user, you don't have to worry about refreshing - and if the app 'reboots', then it should fetch the last saved click counts.

    [Edit]

    I forgot to add, you'll want to include the clickcount incrementer in your button OnSelect: patch update.  Editing the code from the original post, it would look something like this;

    With({buttonRecord: LookUp(ButtonStatesList, Title="Button1")}, 
    
    If(IsBlank(buttonRecord.State), 
    
     Patch(ButtonStatesList, Defaults(ButtonStatesList), {Title: "Button1", State: "On", buttonClicks: 1}), 
     
     Patch(ButtonStatesList, buttonRecord, {Title: "Button1", State: If(buttonRecord.State="Off", "On", "Off"), buttonClicks: buttonRecord.buttonClicks+ 1})
    )
    
    )

    Try it out and let me know how it goes 🙂

    Kind regards,

    RT

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hello @RusselThomas

    Its recording to the sharepoint list but i getting error when i am adding the code OnStart: 2.PNG 

     

  • RusselThomas Profile Picture
    4,014 on at

    Hi @Anonymous ,

    Apologies, I was trying to adapt the commas to your semicolons and didn't concentrate on the format properly.

    Each line should be a row of data, so therefore encapsulated in { }

     

     

    ClearCollect(collectClickColours,
     {numClicks: 1, fillColour: Green},
     {numClicks: 2, fillColour: Yellow},
     {numClicks: 3, fillColour: SkyBlue},
     .....
     {numClicks: 7, fillColour: Transparent}
    )

     

    If your region code requires ; instead of , then just replace them.

     Hope this helps,


    RT

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 395 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 260 Most Valuable Professional

Last 30 days Overall leaderboard