Clearing listbox data when changes web pages

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.


Each page is SHOWn with a menu command: PageA.Show.
I’m not sure how to set the page Implicit Instance OFF, but I’ll look for how to do that.


instead of PageA.Show
it is
var p as new PageA
a new object and you have to remove it somewhere

Implicit Instance is a option at the page, at inspector,behavior, a on/off switch

@MarkusR Thanks, I found both. One question. If I have a Select Case can I do something like:

var p as webpage
Select case SomeVar
Case “Page A”
p= New PageA
Case “Page B”
p=New PageB
End Select

Thank you @MarkusR and @Tim_Parnell for showing us how to create the new pages. I do it this way but I have two doubts:

  • Why should we deactivate “implicit instance” since it is activated by default in Xojo?.

  • It is very easy to create the new pages but how and when do we close the page so that it is not stored in memory (as Tim says)?.

Thank you very much.

Best regards,

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).

@Eric_Bolt1 Yes, you can do that.

1 Like

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

Is that correct?.

you must use the variable where you store your object.
you have to memory your page objects or use this list

Thanks Markus, clarified. I check it today.


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 :wink: .

You are absolutely right @Jeannot_Muller :sweat_smile:

But that’s what the forum is for, to show us newbies the way to follow… :wink:


1 Like

In the Session I have created a property for each web page and I have put in type the name of each web page:

Property (Name: Web1; Type: WebPage1) and
Property (Name: Web2; Type: WebPage2)

Next I create a method in Session to show each page:

Method: ShowWeb1
Web1 = New WebPage1
Method: ShowWeb2
Web2 = New WebPage2

I create a button in WebPage1 and add this code in the ‘Action’ event:

Session.Web1.Close //Close the previous page.  
Session.ShowWeb2 //Open the new page.

Finally I add in the WebPage2 another button to check the number of pages shown with:

When debugging the application, the number of pages increases. The “close” of the web page does not work.

I ask for your advice to learn what would be the best way to implement what you have commented.

I hope I have explained myself, if not I attach an example.


I have tried with this code:

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

But I get an error. Why?

Loop backwards, from Session.PageCount-1 downto 0

Thanks @Hector_Marroquin ,

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.

Link: Example_Implicit Instance

Thank you very much to all.

Guys (@Tim_Parnell or @MarkusR), could you help me to solve the problem, please?. I am stuck.


Hi Sergio,

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.

Best wishes,
Tim Parnell

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”.


That’s for Xojo to decide. Here’s a simplified project that shows the PageCount never goes down: ever_increasing_pagecount.xojo_xml_project

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.