# Set Global Variable in Main Layout

**URL:** <https://forum.radzen.com/t/set-global-variable-in-main-layout/8461>\
**Category:** Blazor Server\
**Created:** [July 12, 2021, 12:56pm UTC](https://forum.radzen.com/t/set-global-variable-in-main-layout/8461 "2021-07-12T12:56:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohnnyOpcode](https://forum.radzen.com/letter_avatar_proxy/v4/letter/j/a183cd/32.png) [@JohnnyOpcode](https://forum.radzen.com/u/JohnnyOpcode)\
**Post date:** [July 12, 2021, 12:56pm UTC](https://forum.radzen.com/t/set-global-variable-in-main-layout/8461/1 "2021-07-12T12:56:05Z")

</div>

I tried to set-up several Global variables in the Load() of the Main Layout. Code generation doesn't seem to work like it does when this is done on a page Load().

Is this behavior on purpose? Am I missing something?

Johnny

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [July 12, 2021, 4:03pm UTC](https://forum.radzen.com/t/set-global-variable-in-main-layout/8461/2 "2021-07-12T16:03:26Z")

</div>

Worked normally for me:

 ![image](https://forum.radzen.com/uploads/default/original/2X/6/624aad8f7d44fe76a3a5457fc7b1ebed548edd5e.png)  
 ![image](https://forum.radzen.com/uploads/default/original/2X/0/09e21751880dbf21b7278b1b40580c2f7be05915.png)  
 ![image](https://forum.radzen.com/uploads/default/original/2X/2/2777820c8c7e7cb2d24fd0ea3c1329a640dfe55a.png)

---

<div class="post-metadata">

**Author:** ![JohnnyOpcode](https://forum.radzen.com/letter_avatar_proxy/v4/letter/j/a183cd/32.png) [@JohnnyOpcode](https://forum.radzen.com/u/JohnnyOpcode)\
**Post date:** [July 12, 2021, 5:05pm UTC](https://forum.radzen.com/t/set-global-variable-in-main-layout/8461/3 "2021-07-12T17:05:45Z")

</div>

My Global variable is a string. I've tried to navigate off of the layout too, but it is not generating the code in the GlobalService. I put it in the Load() event btw.

Weird!

---

<div class="post-metadata">

**Author:** ![JohnnyOpcode](https://forum.radzen.com/letter_avatar_proxy/v4/letter/j/a183cd/32.png) [@JohnnyOpcode](https://forum.radzen.com/u/JohnnyOpcode)\
**Post date:** [July 12, 2021, 5:17pm UTC](https://forum.radzen.com/t/set-global-variable-in-main-layout/8461/4 "2021-07-12T17:17:40Z")

</div>

Aha! Code generation doesn't occur when you move to other layouts or pages, but it does when you run the app from Radzen IDE. I'm using Visual Studio 2019 to debug and watch code. Okay, this gives me a workaround.

Thank-you.
