I have many webpages in an app. Every page has listboxes that are loaded when the page is loaded. The problem is that data is kept when the user moved from one page to the next. How do I fix this?
Page A and Page B both use the same menu.
When a page is loaded, each listbox loads its own data from the database.
All is fine on the first load. But when the user wants to change BACK to a page, I want the data in the list box cleared. This is because the user may have selected something in the listbox and that fills other controls with data.
Here he what I tried so far:
In the SHOWN even for a webpage - ListboxA.deleteallrows
In the CLOSE event for a listbox - ListBoxA.deleteallrows
Yet when the user changes pages (with the menu - which calls the SHOW event for the page) the list box still has old data.
I remember for desktop, in the old days, Iād hide this listbox and update it, then show it again. Is this an option?
Like I say, the listbox will update but still shows the old data until the update is complete. Who has sum suggestions for me to try?
How are you showing the pages? On Web you need to explicitly close a page otherwise it stays open in memory.
Iād recommend that you turn the page Implicit Instance off and be sure to show a new page every time. Iād link Bobās post about why implicit instance is evil, but weāve since lost that resource.
Hereās the wayback machine archive for Bobās now lost blog post. Itās a shame Xojo isnāt trying harder to keep professionals around. Implicit Instance is Evil | BKeeney Briefs
Any time you have Page.Show, do Self.Close right after (unless you specifically want to keep the old page around).
Thanks guys (@Tim_Parnell and @MarkusR ). I have reviewed Bobās article and if you who are more Xojo experts recommend disabling implicit instance I guess it will be justified. I will give it a try.
Regarding Self.Close, if I understand correctly when going from pageA to pageB I would have to use this code:
var b as new PageB
PageA.Close //Close the previous page
b.Show //Display the new page
Well, I can only guess, but they probably activate it my default to make it easier for beginners (less code and working āout-of-the-boxā), but as with many program default settings these donāt necessarily reflect the best approach for more experienced users .
For i As Integer = 0 to Session.PageCount-1
If Session.PageAt(i) <> Session.PageWithName("WebPage1",True) Then
Session.PageAt(i).Close //Close the previous page.
Session.ShowWeb2 //Open the new page.
End If
Next
now it doesnāt give error when clicking on the button the first time but the pagecount keeps increasing 1 page each time you click on it. And when going to the second page and returning to the previous one it gives error.
Any suggestions?
I attach an example file in case someone does not understand me well and is encouraged to help me.
I looked at your example project, and even tried simplifying it; but the PageCount continued to increase. It could be a framework bug, I canāt explain why it would be happening.
Thank you Tim for reviewing the example. But then does this mean that the web pages are not closing or is PageCount failing?. Depending on what you tell me I can create a bug report in āFeedbackā.