Wisej controls have a very useful reference to their hosting Window (Form) with a FindForm() method. However, if a control is hosted in a Page (and not a Form) there is no equivalent FindPage() method.
Initilally I thought that since only one page is visible at a time, we may not need such a method, and replace it with the Application.MainPage property. However, an application might have more than one Pages, and different sessions of the application may show different pages on a certain moment. So I don’t know what Application.MainPage would return to those different sessions.
Am I missing something?
“Statics” in a web application are always a concern, especially when migrating winforms code.
With Wisej you can move the equivalent of statics to session variables using Application.Session. It’s a dynamic object so you can:
Application.Session.myName = "Luca"; Application.Session.myAge = 21; // :)
No need to use strings and indexers and casting. It’s all automatic. You could also wrap all your app static in a single class, say Statics, and assign an instance of that class to Application.Session.
In the case of button A (a child of Page1), TopLevelControl will return Page1 since it’s the top level parent.
In the case of button B (a child of Form1), TopLevelControl will return Form1, it’s top level parent.
There is no hierarchy or relation between Page1 and Form1: if you change the main page to Page2, you still have the forms on the screen.
If you are coding in the context of button B you have to use Application.MainPage to refer to the currently active page, if there is any. While if you are coding in the context of button A, use TopLevelControl to refer to its parent page. The page is simply a low z-order control that fills the browser. Any form will display in front of it.
Application refers to the session only. Different sessions can have different main page or main desktop, etc. Anything you change in Application is always relative to the user/session.
You can use this.TopLevelControl. It will return the very top level container, in the your scenario it’s the Page. You need to cast it.
FindForm() always finds that first container Form, even if it’s not the top level: it can be an mdi child, or an embedded child form. For example, an MdiChild is not a top level control, an Mdi Parent is. An embedded child form is not top level, etc.
Let me know if TopLevelControl works for you.