# Page - Reload is changing state back to default (ui-template,DB2)

**URL:** <https://discourse.nodered.org/t/page-reload-is-changing-state-back-to-default-ui-template-db2/88109>\
**Category:** Dashboard\
**Tags:** dashboard-2\
**Created:** [20 May 2024 01:14 UTC](https://discourse.nodered.org/t/page-reload-is-changing-state-back-to-default-ui-template-db2/88109 "2024-05-20T01:14:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xx\_Nexus\_xx](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xx\_Nexus\_xx](https://discourse.nodered.org/u/xx_Nexus_xx)\
**Post date:** [20 May 2024 01:14 UTC](https://discourse.nodered.org/t/page-reload-is-changing-state-back-to-default-ui-template-db2/88109/1 "2024-05-20T01:14:33Z")

</div>

Hi, this scenario might have been asked already but I could not find it

I'm currently migrating to DB2 and want to create a default header for all my switches and lights.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/8/d8321a52725dc3b0d415b8875945a380813ac1f7.png)

Unfortunatelly, any page-refresh (F5 or moving away and back to this page) will reset to above default state

Example:

1. Page is newly loaded .. showing default state  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/8/d8321a52725dc3b0d415b8875945a380813ac1f7.png)

2. Switch the light ON by clicking the "ON" button  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/5/358c7236d4df0e2fb1234cbd476bf1e45cfbd843.png)

3. pressing F5 / refresh the page .. resetting to default  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/8/d8321a52725dc3b0d415b8875945a380813ac1f7.png)

Please see code for ui-template here  
[header.json](https://discourse.nodered.org/uploads/short-url/7KblnwUiJfDyyrjGJRY5hV851HL.json) (4.2 KB)

How can I ensure that the state is maintained and only changed by user click on any of the elements?

thank you for your help

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [20 May 2024 09:24 UTC](https://discourse.nodered.org/t/page-reload-is-changing-state-back-to-default-ui-template-db2/88109/2 "2024-05-20T09:24:45Z")

</div>

When you refresh the page the last message received by or sent by the template is replayed to the template. You have to ensure that the message you send includes information needed to correctly show the state.

If you add, in your template, in the watch msg function the line

```auto
console.log(`Message received: ${JSON.stringify(this.msg)}`)

```

and view the developer console in the browser then you will what message is being sent when you refresh the page.

---

<div class="post-metadata">

**Author:** ![xx\_Nexus\_xx](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xx\_Nexus\_xx](https://discourse.nodered.org/u/xx_Nexus_xx)\
**Post date:** [22 May 2024 00:11 UTC](https://discourse.nodered.org/t/page-reload-is-changing-state-back-to-default-ui-template-db2/88109/3 "2024-05-22T00:11:52Z")

</div>

Hi Colin,

I did add the line, but there is no debug output when a page refresh(F5) is happening ..looks like there is no update/change to "msg" while refresh ☹  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/1/71f88dcd678fd98cbcf833b73c4a8557e596c832.png)

I did the same in the aree to check when btn is clicked .. and output is showing for that

Any other idea?

Have you been able to see the same on your end when using my json code?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 May 2024 06:47 UTC](https://discourse.nodered.org/t/page-reload-is-changing-state-back-to-default-ui-template-db2/88109/4 "2024-05-22T06:47:07Z")

</div>

Can you post your updated flow please. Please post it inline rather than a file. In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [21 June 2024 06:47 UTC](https://discourse.nodered.org/t/page-reload-is-changing-state-back-to-default-ui-template-db2/88109/5 "2024-06-21T06:47:21Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
