[SOLVED] FindPage method

Answered Closed
0
0

Hi,

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?

Best,

Alex

  • You must to post comments
Best Answer
0
0

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.

Best,

Luca

  • You must to post comments
0
0

Hi Luca,

  1. Imagine the following scenario: A Page with a button A. Clicking button A opens a Window (Form) which has a button B in it. What I am asking is whether there is a single property for both buttons, A and B, pointing to the Page. As I understand, buttonA.TopLevelControl is the Page, but buttonB.TopLevelControl is the Window. Am I correct?
  2. Can I remind you the question in my original post “what will two different sessions return when they call Application.MainPage, if these two different sessions show two different pages at a certain point of time” ? Does “Application” refer to the web application running in the virtual directory of IIS? The reason I am asking is that once I had a terrible problem with application-level variables in a multi-tenant application which were meant to show different things for different tenants.

Best regards,

Alex

  • You must to post comments
0
0

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.

Best,

Luca

  • You must to post comments
0
0

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

Best,

Luca

 

 

  • You must to post comments
0
0

Hi Luca!

All clear, if Application is user/session relative.

And this Session.MyVar is extremely useful. Thanks for this tip!

Alex

PS. 21??!!! 🙂

  • You must to post comments
Showing 5 results