Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

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.
Posted
Sorry that first part is done in a webfrom
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.
Posted

This is beter

 

Public Class Class1

 

Sub New()

 

End Sub

Public Function run() As String

 

Return HttpContext.Current.Application("test")

 

End Function

End Class

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...