Web Navigation

I’ve been spending a lot of time in the documentation and this forum and still can’t get this to work.

I have a weblistbox that will navigate to a detail page if the user clicks a button to view details. Here is the contents of that button.

if lbRecords.SelectedRowIndex > -1 then

var nID As Integer = lbRecords.RowTagAt(lbRecords.SelectedRowIndex)
Session.SaveState(“YourClassListing”,nID.ToString)
Session.ID_ReadOnly = nID

var wContactInfo As New ContactInfo
wContactInfo.Show

The nID variable contains the record ID selected when the button is pressed to see the details.

That works fine. If the user then clicks the “back” button, I expected the session.hashtagchanged event would fire which it does, but the parameters of the hashtagchanged (name and data) are blank. Is this because I’m running in debug mode as opposed to xojo cloud? I just want to make sure that I’m doing this correctly.

I believe that by using the ‘Back’ button in the browser you’re essentially reloading the App/Session, creating a new Session. You should put navigation items in your App, letting Xojo go from WebPage to WebPage in the App. Hope that makes sense.

Have you tried with placing Session.SaveState("page-name") in the Shown event of your WebPages?

1 Like

Willian - Is there some way to prevent them from using the back button thereby causing a new session to be created?

Look into what @Gabriel_Ludosanu said. You can get the back button to actually go back to a page in your app with that technique

The instantiated name or the actual name of the page?

any name you like. you can then use the name you set, in Session.HashTagChanged or Session.Opening events to directly load a specific page, etc.

Gabriel

when they press the back button how will it know to redisplay that page. I’ve tried putting that in the shown event of a web page but nothing seems to happen when I press the back button on a subsequent page selected.

Is this because when they press the back button it actually is terminating the session and opening a new one?

Using SaveState won’t create a new Session.

You need to implement the Session.HashtagChanged event with something like

  Select Case name
  Case "page1"
    Var w As New WebPage1
    w.Show
  Case "page2"
    Var w As New webpage2
    w.Show
  End Select

where page1 and page2 are the values you used for your pages with SaveState.

Don’t forget that SaveState can actually take 3 parameters.

Name as String
Data as String = “”
Replace as Boolean = False

I find that the simplest way to use this is to call SaveState whenever something significant happens that you might want the user to be able to go back to. For instance:

  1. On Page.Shown, just the name.
  2. User fills out fields and submits, maybe name and data.

Now this feature is a stack, so every time you save state, another entry is put on the stack. If you want to replace the most recent item, you set the Replace parameter to True.

You may also consider to display the ContactInfo in a webdialog. This way the user still sees the window in the background which helps them keep track of where they are in your app.