Menu click events won't consistently interact with page controls

Hi Guys, I saw a post about this from some months ago, but I'm not sure I understand it. I'm setting a global variable that's used as the visibility property for a control. If I toggle the variable with a control that is on the same page, it works perfectly. But If I toggle the same variable with a menu click event, the control's visibility doesn't change most of the time. It does on random occasion.

Stepping through the code, I can see that the menu click event is changing the variable properly, but the fact that it's being changed from a menu click event seems to cause it to not work. It doesn't seem to matter if I initially set this global variable in the layout load event or the page load event.

Here is the menu click event code -

        protected async System.Threading.Tasks.Task Menu0Click(MenuItemEventArgs args)
        {
            if (args.Text == "Show Set Dept") {
                Globals.showUserDeptRadios = true;
            }

            if (args.Text == "Hide Set Dept") {
                Globals.showUserDeptRadios = false;
            }
        }

Any thoughts?

Thank you,
Slosuenos

Try the following:

  1. Handle the Change event of your page
  2. Add Execute C# action with Code set to StateHasChanged()

Find attached a sample app.
MenuGlobalProperty.zip (25.6 KB)

1 Like

Will try, thanks @korchev !

Slosuenos

Worked perfectly, thanks man!
Slosuenos