Referencing global.asax variables?

windows

Guest
techies:
when i debug the app, the gstrTimerstart is set correctly, however in the load event of the index.aspx i create a reference to global class and the variable is set to nothing. thank you in advance for any ideas.

i have this code in my global.asax.vb file:
Public Class Global
Public gstrTimerstart
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
gstrTimerstart = fncTimer() 'get current time app starts
End Sub
End Class


in index.aspx file code behind:
Dim gbl As Global = New Global
Dim strHTML As String
strHTML += "App Start Time:" & gbl.gstrTimerstart <--no value here
debugPanel.InnerHtml = strHTMLYou are instantiating a new instance of class global and gstrTimerstart will be set to nothing. You should use an application state variable to get what you are trying to achieve like this.


Public Class Global
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
Application.Add("gstrTimerstart") = fncTimer()
End Sub
End Class


You can retrieve the value like this:

Dim strHTML As String
strHTML += "App Start Time:" & Application.Item("gstrTimerstart")
debugPanel.InnerHtml = strHTML


PS. I used the Application_Start Event, because that is the first event fired when your app is started. Also, in case you are not aware of this. Your application will stop if it is not being used for a given amount of time and start back up if used. This is done to preserve resources. That means all Application events may occur over and over.Cstick,
Thanks alot! This helps tremendously. I will apply your suggestion about moving the code as well. keep up the great work and have a good one!
mcrpds
 
Back
Top