How best to use SaveState and HashtagChanged to preserve current page?

Hi all. I have some of my web app users experiencing the “We are having trouble communicating with the server. Please wait a moment while we attempt to reconnect.” and then the app redirects them to the login page. I was researching the forum a bit and found SaveState and HashtagChanged and wondered if adding these could help. But I am not fully sure where to add them and how to use them, if these could actually help.

In addition, I would like to handle the user clicking the Back/Forward browser buttons as well as the browser Refresh button. In a small test app, Back/Forward seems to work for the SaveState (set in a button.Pressed event to go to another page Session.SaveState("wpNew", "", False)), but the refresh button still takes me back to the home page and looks to reset everything

I did check out the Using Hashtags example project, and that seemed to handle the back/forward/refresh well, but the example is too basic, and I don’t know how to apply this to my app with a lot more than just maintaining the selected row.

It would also be helpful to know how to simulate showing the Interrupt Message. I have experienced the message in my live app on rare occasion, but I don’t know what sparks it. I tried disconnecting from wifi and also pausing the running app, but that didn’t seem to bring up the message to test to make sure any changes I make have an effect

This is for an app hosted on Xojo Cloud, running 2025 R2

Try using a WebCookie to save which page is displayed and any info the user has entered. Then when the app reconnects, if a cookie is available, ask the user if they want to restore the session. Read the cookie info to restore the user fields.
Thanks

This issue may come from a timeout (processing to long) or having not enough cpu space or the connection is lost somehow.

The savestate stores the given data but i’m not sure where it is stored, therefore i’d advise you to store your user data somewhere save and have a secure (encrypted or such) cookie that expires for the login. So that when the Session.Opening event is run, you check the login cookie on validity and move the user to the correct page.

SaveState is meant so that if the hashtag changes, the page will go to the state that was saved with that name.

1 Like

Derek’s probably correct that something you’re doing on the server is taking too long and needs to be threaded.

As for SaveState, this is a generally misunderstood feature. SaveState allows you record the current state so that the browser’s Back and Forward buttons work as expected. When you call SaveState, you tell it two things, a name and state info. I typically use a name for the page the user is on and a json string with state info. This adds an item onto the browser’s history stack. Each time the user does something significant that they may want to go back to, you save the state. The last parameter lets you replace the current state. So if the user were filling out a form, you could replace every time you validated the form so coming back to the page would result in the form being fully filled. When the user presses the back button, Session.HashTagChanged fires and gives you the name and state information that were stored so you can send the user back to that exact spot. Keep in mind that recording the state when you’ve moved backwards will clear any of the forward stack.

1 Like

Yes, I am wondering about this too. I’ll have to look back at all my processes and start improving/threading them one at a time. It doesn’t sound like SaveState is what I need. Appreciate the info on the

Thanks for the responses