Refresh label with Global property value

My user is assigned to a plant. The main form shall show always the user name and the plant. I put two labels in the main layout: labelUserName, labelPlant
I add a global Property GlobalPropUserPlant (as string)
Then I bind the label to Globals.GlobalPropUserPlant

Then I add in Login.razor.cs into the class LoginComponent the method

            Globals.GlobalPropUserPlant = "Ulm";
            return plantId = 1;

When I run the app in the debugger I see Globals.GlobalPropUserPlant gets the value "Ulm", but it does not update the labelPlant.


Hi @Claus_Kessel,

You can add the following code to the Layout Load event:

This does not work.
First I have to set the property , if I do not set the property Globals is empty
To set pthe property and thean execute is also no solution:
I checked in Visual Studio the ...cs file:

            Globals.GlobalPropUserPlant = "ulm";
            Globals.PropertyChanged += (e)=>StateHasChanged();

From my understanding Load() always replaces GlobalPropUserPlant with "ulm".
I tried this:

static int ulmCount = 0;
        protected async System.Threading.Tasks.Task Load()
            Globals.GlobalPropUserPlant = $"ulm_{ulmCount}";

Now it updates each load event the label with "ulm_0", "ulm_1",...

But when I change Globals.GlobalPropUserPlant in a methode in Login.cs then it does not work:

----------in Login.razor --------:
        <RadzenTemplateForm Action="@($"account/login?redirectUrl={redirectUrl}")" Data="@("login")" Method="post">
            <RadzenLogin AllowRegister="false" AllowResetPassword="false" Login="@Login0Login" Register="@Login0Register">

---- in login.razor.designer.cs---
        protected async System.Threading.Tasks.Task Login0Login(dynamic args)
            var getUserPlant4UserIdResult = GetUserPlant4UserId(1);

---- in Login.razor.cs ------------
         public int GetUserPlant4UserId(int userId)
            int plantId = -1;
            if (userId == -1)
                return -1;
            Globals.GlobalPropUserPlant = "Weingarten";
            return plantId;

I'm a beginner, perhaps this is the wrong way.
What I want is the user name and the city name (which is assigned to the user) in the header of the main layout.

Try adding this code in the Load event of the layout.