Is there a way to get a handle to a WebPage by name?

I’m trying to get a handle to a webpage that the user has NOT opened yet (searching through the pages in their session won’t help).

Is there a way to do this with introspection or a method I haven’t been able to find?

In a nutshell, I’m looking for something along the lines of this:

MyApp.GetWebPageByName(SomePageName).show

Here’s a more detailed explanation of my usage scenario in my web application:

The app has dozens of WebPages (pageX, pageY, pageZ, etc.).
Depending on which user has logged in, they are presented with a menu corresponding to a subset of the pages (for example, just pageX and pageZ).
Based on their selection, the appropriate WebPage is opened.

In the past, I have done this using either If/Then/else or Select Case statements covering every possible WebPage (with their names hard-coded and each case going to a separate hard-coded line for that specific WebPage (PageX.show)

I’d really like to get rid of the If/Then/Else and Select with their dozens of lines of hard-coded page names and replace them with a single line something like this:

MyApp.GetWebPageByName(SomePageName).show

or even 2 lines:

dim NextPage as WebPage=SomeMethodThatGetsMeThePageByName(SomePageName)
NextPage.show

Help appreciated!

Hi Seth,

Not sure if my suggestion would be of any help. But, in my little app, instead of defining several WebPages, I only have one main WebPage and all contents is included through ContainerControllers. I have a top-level container controller MainFrameUI, and within that i have several othre container controllers such as ProjectsUI, UsersUI and the like.

I now can make invisible/visible the whole page via MainFrameUI.visible=false, which is useful for the login dialog, when all else is hidden; and I can selectively present different UIs as needed.

The drawback is that it doesn’t look good in the IDE to have all those controllers piled into one WebPage window.

Perhaps in your case you can distill Web Pages into a smaller number each having containercontrollers.

Dan

[quote=184542:@Seth Ober]I’m trying to get a handle to a webpage that the user has NOT opened yet (searching through the pages in their session won’t help).

Is there a way to do this with introspection or a method I haven’t been able to find?

In a nutshell, I’m looking for something along the lines of this:

MyApp.GetWebPageByName(SomePageName).show

Here’s a more detailed explanation of my usage scenario in my web application:

The app has dozens of WebPages (pageX, pageY, pageZ, etc.).
Depending on which user has logged in, they are presented with a menu corresponding to a subset of the pages (for example, just pageX and pageZ).
Based on their selection, the appropriate WebPage is opened.

In the past, I have done this using either If/Then/else or Select Case statements covering every possible WebPage (with their names hard-coded and each case going to a separate hard-coded line for that specific WebPage (PageX.show)

I’d really like to get rid of the If/Then/Else and Select with their dozens of lines of hard-coded page names and replace them with a single line something like this:

MyApp.GetWebPageByName(SomePageName).show

or even 2 lines:

dim NextPage as WebPage=SomeMethodThatGetsMeThePageByName(SomePageName)
NextPage.show

Help appreciated![/quote]

Until a page has been instanciated I see no way to get any information from it. Maybe what you could do is use a dictionary into which you place insatnces of all your web pages.

I tried this with a module d property as Dictionary, then :

In app :

Sub Open(args() as String) d = new dictionary End Sub

In Session :

[code]Sub Open()
d.value(“WebPage11”) = new Webpage11

End Sub
[/code]

In a button on main page :

[code]Sub Action()
webpage(d.value(“Webpage11”)).show

End Sub
[/code]

That allows you to call a page with a string value instead of hard coding.

Would creating a dictionary in that manner pre-create an instance of every page for every session? I’d be concerned with the resources (memory/cpu) used when there are 100+ simultaneous users?

Don’t do that unless you’re going to use WeakRefs. You’ll create a memory leak that will prevent sessions from quitting.

If you want something like this, I’d suggest that you use the names of the pages as keys and make the value the number of times it has been opened. You could override the Show method like this:

Sub ShowPage(extends page as WebPage) Session.PageCounter.Value(page.name) = Session.PageCounter.Lookup(name,0) + 1 Page.Show End Sub

Then all you’d need to do is query the dictionary:

timesOpened = Session.PageCounter.Lookup(page_name,0)

Just make sure you declare the property on the Session object so you get one per session.

You got the answer from Greg.

Select case seems in order.