I'm self-traning on ASP.NET and am using the code below to figure out data caching. It gets several errors...how
should I rewrite it to make it work? (I expect I'm making several incorrect assumptions here about scope, etc... hopefully in the process of figuring this example out I'll learn more about those things, too!)
Learning objective here is to put something in data cache on one page's event, and then get it out on another page's event...
Thanks!
'--------------------------------------
Partial Class Pages_AddCache
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim AddCache As New AddCache
AddCache.Add()
End Sub
End Class
'--------------------------------------
Partial Class Pages_GetCache
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim GetCache As New GetCache
GetCache.Retreive()
End Sub
End Class
'---------------------------------------
Imports Microsoft.VisualBasic
Imports System.Web.Caching
Public Class AddCache
Public CC As New Cache
Sub Add()
CC("Test") = "Test" '<===System.NullReference Exception: Object reference
'not set to an instance of an object
msgbox("input " & CC("Test") )
End Sub
End Class
'---------------------------------------
Imports Microsoft.VisualBasic
Imports System.Web.Caching
Public Class GetCache '<=== seems either this overrides the public
' declare of CC above, or
Dim CC As Cache
Sub Retreive()
Dim aString As String = CC("Test") '<=== if not declared in this
' sub, says CC not declared
MsgBox("output " & aString)
End Sub
End
should I rewrite it to make it work? (I expect I'm making several incorrect assumptions here about scope, etc... hopefully in the process of figuring this example out I'll learn more about those things, too!)
Learning objective here is to put something in data cache on one page's event, and then get it out on another page's event...
Thanks!
'--------------------------------------
Partial Class Pages_AddCache
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim AddCache As New AddCache
AddCache.Add()
End Sub
End Class
'--------------------------------------
Partial Class Pages_GetCache
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim GetCache As New GetCache
GetCache.Retreive()
End Sub
End Class
'---------------------------------------
Imports Microsoft.VisualBasic
Imports System.Web.Caching
Public Class AddCache
Public CC As New Cache
Sub Add()
CC("Test") = "Test" '<===System.NullReference Exception: Object reference
'not set to an instance of an object
msgbox("input " & CC("Test") )
End Sub
End Class
'---------------------------------------
Imports Microsoft.VisualBasic
Imports System.Web.Caching
Public Class GetCache '<=== seems either this overrides the public
' declare of CC above, or
Dim CC As Cache
Sub Retreive()
Dim aString As String = CC("Test") '<=== if not declared in this
' sub, says CC not declared
MsgBox("output " & aString)
End Sub
End