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
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?
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.
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?
Application is not global. It refers to the single session, just like Application in WinForms.
Please login first to submit.