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 / Toggle OnChange event,...
Power Apps
Answered

Toggle OnChange event, when fired from a button, executes twice instead of once

(0) ShareShare
ReportReport
Posted on by 143

Hello, 

I have created a demo app where a button fires a toggle control, and to my surprise (or to my misunderstanding) the toggle OnChange event is running twice instead of once.

 

So I have:

- a variable named tmpcounter that OnStart of the App is set to 0

- a toggle control which its default value is based on a boolean variable (tmptoggleflag). This variable is initially set to false on the OnStart App event

- a button that, OnSelect, sets the boolean variable tmptoggleflag to true, to trigger the toogle

- the toggle OnChange event sets the boolean variable tmptoggleflag to false  and increases the counter tmpcounter +1

 

When I run the sample application, every time I click the button, the counter tmpcounter is increased by 2, not by 1, so it looks like the OnChange event of the toggle is firing twice instead of once.

 

How/why is that possible ? What am I missing ?

 

Shouldn't the counter increase only by 1 ? Or what should I do so the toggle OnChange event is only fired once ?

Categories:
  • Verified answer
    GarethPrisk Profile Picture
    2,828 on at

    Boolean controls have an OnChange, OnCheck (True), and OnUncheck (False).

    At times, you can accidentally get into a recursive loop where the Toggle is being changed by a function which changes it again.

    Instead, consider using OnSelect to set the value, or hook the explicit true or false triggers.

  • vllanso Profile Picture
    143 on at

    Thank you Gareth, that was fast !

     

    I have moved the code from the OnChange to the OnCheck event of the toggle, and certainly now it is working as I expected and the counter is increased only once.

     

    Thanks again !!

  • TB-13091842-0 Profile Picture
    140 on at

    I've been working on a matter like this and was running into some toggle problems. Your solution worked because OnCheck only triggers when the value changes to true. The OnChange action is triggered whenever the variable changes, whether from false to true or from true to false. So you triggered the action once when you changed it to true in the button, and triggered it a second time when you changed it from true to false in the OnChange action.

    You can get around this another way: the button sets the Variable = !Variable, and then the original action in OnChange, minus the Variable change, will fire only once.

    These both accomplish the same goal, but changing the Variable only once is cleaner.

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 411 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 338

#3
WarrenBelz Profile Picture

WarrenBelz 256 Most Valuable Professional

Last 30 days Overall leaderboard