dynamic page click counter help

Hello, I am trying to set up a click counter on a dynamic page.

• In each dynamic page there’s a button #button1 and a dataset #myDataset
• In the dataset there’s a number field named “clicks” and it’s value in the sandbox is 0
• In each dynamic page there’s a text item #text1 connected to the “clicks” field in the database.

Here’s the code I put in my dynamic page:

export function button1_click(event) {
 const currentItem = $w("#myDataset").getCurrentItem();
 let clickCount =  currentItem.clicks + 1;
    $w("#myDataset").setFieldValue("clicks",clickCount);
    $w('#myDataset').save();
}

This code works fine so when I click the button #button1 , the text inside #text1 shows a number that increases at every click.

The problem here is that when I reload the page, the number inside #text1 resets back to 0.

Can anyone help me fix this issue? Please don’t forward me back to other posts on the forum as I already tried probably everything posted in other posts and I wasn’t able to make this work.
Thanks in advance!

Please refer to the following:
https://www.wix.com/corvid/reference/wix-storage.html
You probably need to store the click count in #text1 as session storage.

Hello, @theredeng :raised_hand_with_fingers_splayed::raised_hand_with_fingers_splayed:

You just need to set the fields value and save the dataset on each click, you can disable the button during that process and enable it once it’s done.

Hope that help
Ahmad