hankthetank Posted February 27, 2004 Posted February 27, 2004 I have created several Application variables in an ASP.Net solution. I can manipulate these variables fine in a Web Form code-behind page but for some reason I get an error when I try to use them in a VB code page. I am converting ASP pages to .Net and I have converted any ASP include pages into a Public Class in a .vb page. For example; index.aspx.vb Public Class Index Inherits System.Web.UI.Page Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Response.Write (Application("CommsURL")) ' this works fine Dim clsOption As New _Option Response.Write (clsOption.DisplayAppVar()) clsOption = Nothing End Sub End Class option.vb (this was previously the ASP include file) Public Class _Option Inherits System.Web.UI.Page Public Function DisplayAppVar() DisplayAppVar = Application("CommsURL") ' this generates an error End Function End Class The error generated by the line above is "System.NullReferenceException: Object reference not set to an instance of an object." I have tried creating an instance of the System.Web.HttpApplication class as follows ; Dim clsHttpApp as new System.Web.HTTPApplication DisplayAppVar = clsHttpApp.Application("CommsURL") but still get the same error.....Can anyone please help??? I'm tearing my hair out here!! Thanks Matt Quote
Bodybag Posted February 27, 2004 Posted February 27, 2004 Dim c As New Class1(Application) Label1.Text = c.run() Public Class Class1 Dim appweb As Web.HttpApplicationState Sub New(ByVal app As Web.HttpApplicationState) appweb = app End Sub Public Function run() As String Return appweb.Item("test") End Function End Class Quote Programmers are trying to create bigger and beter idiot proof programs.The universe is trying to create bigger and beter idiots and so far the universe is winning.
Bodybag Posted February 27, 2004 Posted February 27, 2004 Sorry that first part is done in a webfrom Quote Programmers are trying to create bigger and beter idiot proof programs.The universe is trying to create bigger and beter idiots and so far the universe is winning.
Bodybag Posted February 27, 2004 Posted February 27, 2004 This is beter Public Class Class1 Sub New() End Sub Public Function run() As String Return HttpContext.Current.Application("test") End Function End Class Quote Programmers are trying to create bigger and beter idiot proof programs.The universe is trying to create bigger and beter idiots and so far the universe is winning.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.