Application.Mainpage lost after Main

0
0

Hi,

I don’t get the Application class behaviour.

On starting a new (VB) wisej page app.,  a VB module is automatically created with a Public Sub Main() as follows:

Public Sub Main()

Application.MainPage = New Page1

End Sub

Which launches Page1 as the startup page.

However, when another function or sub is called within the same module, “Application.MainPage” is “nothing”.
I.e. MainPage has been reset to nothing somewhere along the line, whereas I thought Application was global?

I’m probably misunderstanding the general purpose/scope of “Application”, so please explain?

Thank you

Darren

  • You must to post comments
0
0

Application.MainPage is set when the session starts. There is no “application running” on the server that sets or loses MainPage. Different sessions (users, clients) can have different MainPages.

The sample doesn’t set MainPage because the ASPNET ashx handler is a static (stateless) handler that calls a staic method. There is no session. You are adding to a shared (static) list. It would make no sense to have Application.MainPage created or restored without a session.

HTH

  • Darren
    Blimey, Clearly I’m still not understanding the basics. I’m either embarrassingly stupid or web app dev. has a whole new set of magic tricks that I need to learn first, before attempting to actually build anything. Is there any kind of “general principles / concepts” help you could recommend I read before I drive myself insane!? You know what would really go down well for first-time web rookies? A diagram! A diagram clearing showing the scope & usage of web variables/classes & indeed terminology. Half the time I don’t even understand the terminology, let alone the answers. Seriously, I’m going round the bend because I haven’t learnt the concepts.
  • Luca (ITG)
    I’ll send you a direct email with some clarifications.
  • You must to post comments
0
0

Luca,

Simple test attached.

Run it and send a request with params. such that the handler is called, which in turn calls “AddClient” in Program module.

Within AddClient, if you look at Application.MainPage – it is “Nothing”.

Because it’s nothing while the app. is running, what’s the point in setting it in the first place?

Thanks

Darren

Attachment
  • You must to post comments
0
0

Application is not global. It refers to the single session, just like Application in WinForms.

  • Darren
    Hi Luca, OK, sorry I didn’t make the connection between Application in Winforms & Application in wisej. However, this begs the question: Why set Application.MainPage at all? What’s the purpose of doing this if .MainPage is immediately reset to nothing?
  • Luca (ITG)
    It’s not reset to Nothing. I just tried, please send a small test case.
  • Darren
    Hi Luca, Will do tomorrow at work. Meanwhile, you could try: VS 2012 pro / VB. New project > Wisej page. In module > main() > Application.Mainpage = new page1() I have a handler. Send a mapped request to the handler which calls a sub or function in the same module. When that sub is called, check Application.Mainpage. For me it’s “nothing”.
  • Luca (ITG)
    That’s correct. The ASP.NET handler is ASP.NET and has not knowledge of the context or the session, it’s just a static call.
  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.