closed
Public

I am trying to figure out how to make a “Back” button work. I have multiple pages – say 6 pages – named P1, P2, P3, P4, P5 and P6. P1 is where we start.

Each page P2, P3, P4, P5 and P6 has a “Back” button. Clicking the Back button takes the user to the previous page.

But I am having problems as I cannot see how to implement a stack.

If I go P1, P2, P3, P5 – then hit Back I can return to P3, but if I hit Back in P3 I do not return to P2.

Or if I go P1, P2, P3, P6 – then I hit Back I return to P3, but the same problem exists if I hit Back in P3 – how do I get to P2.

Or I go P1, P2, P4, P6 – and so on.

How can I make a Back button always return to the previous page?

Thank you,

Lawrence Hare

4 answers

Hi Lawrence, this can be achieved by using two global properties to trace the current page and previous page.

All page should handle the “Page Loaded” event (you can do it in master page, but the event should be changed to “Loaded as Master Page”):

Then all “Back” button should do this:

This is the minimum implementation, for sure you will need to tweak it to work better.

#1

HI and thank you, that is how I originally coded it, but it failed for cases of multiple levels, i.e. 1 -> 2 -> 4 -> 5 -> 4. “Back” would return to 5, but “Back” from 5 would leave me where I am. I THINK it is because the “Page Loaded” code is executed when I go “Back” from one page to the previous one. In other words, this works if the progression is linear, but if there are gaps or recursion it fails.

Bad explanation – I apologize…

My current fix is to implement a LIFO stack. On any button that will move me to a new page I do a PUSH, on any “Back” button that takes me to wherever I came from I do a POP and a GoTo whatever came off the stack.

I have implemented a 6-level stack which, as I have two pages that are recursive, will fail after a couple of recursions. I think I may up the stack to 8. The recursion is not necessary however and will not come to anyone’s mind unless they are being mischievous!

In short, I need code that is executed ONLY when one page leaves for another and ONLY when one page goes BACK to the previous one. It means a lot of coding (I have a non-executing page which contains two buttons, PUSH and POP. I select the button, select the code and copy and paste it to its new location, then move it to the correct place in the code for the new object – this saves some time)

It would be nice if ForeUI provided a page tracking stack that one could use by referencing the top of the stack – which would be the current page. Then reference the top-1 location of the stack and that would be the previous page. ForeUI would then manage the stack as pages were loaded and returned from. And a nice deep stack too!

Thanks – Lawrence

#2

Hi Lawrence,

Thanks for sharing the idea. It is quite interesting to implement a stack with ForeUI. The best solution in my mind is to make use of the Table element, which can be used as the data repository, and be manipulated with actions.

I created an example for you and others that are interested in this topic: http://www.foreui.com/misc/tmp/PageSt…

The main logic are defined in the “Master Page” (the 5th page). The table could be set to invisible if you don’t want to see it in the page.

#3

Hi and thanks for the response, an interesting idea using a table as an indexed array. What I did was to create a set of integer variables as global properties and then push the current page index whenever I have a button that is going to take me to a new page, then I do a pop whenever there is a “Back” button that I want to return me to the page I came from. I have attached images of the code below – using the “Add image” (Upload) button – not sure if the images can be seen.

By keeping the code associated with the Push and Pop attached to Push and Pop buttons on a page of miscellaneous code, one that is not included in anything, I can open, copy and paste the code wherever I want.

Seems to work fine but beware of stack overflow!

Cheers – Lawrence

#4
  1. Thanks for sharing. The advantange of using Table to store data is that, it has no limitation of the depth, also it will be simpler to use Table instead of managing multiple properties.

This question is now closed