Can't access application object from inside class files

  • Thread starter Thread starter trebor
  • Start date Start date
T

trebor

I added a couple of class files to a VS web project, and I can't access
the application object from inside them. The system treats them like
undeclared variables. Is there an Imports I have to use?

The value that I need global to the entire project is the oleDB
connection string ("Provider=.... Data Source=C:\...").

What I've done in the meanwhile is declare a shared property in each of
the classes to hold this value. When the application starts, I set the
property from the global.asax.vb file. This works, but is it a real
hack?

Is there a better way to establish global constants in VS web projects?
 
If your classes aren't extending System.Web.HttpContext in some way, they're
not going to have access. You'll notice that your aspx pages extend
System.Web.UI.Page. Page has an HttpContext, which means that your
codebehind classes have access. on the other hand, classes that you add
yourself won't have automagic access.

as for the "best" way to have a global constant - I'll let someone else with
more experience than I take a stab at the "best" way to accomplish that.

John

I added a couple of class files to a VS web project, and I can't access
the application object from inside them. The system treats them like
undeclared variables. Is there an Imports I have to use?

The value that I need global to the entire project is the oleDB
connection string ("Provider=.... Data Source=C:\...").

What I've done in the meanwhile is declare a shared property in each of
the classes to hold this value. When the application starts, I set the
property from the global.asax.vb file. This works, but is it a real
hack?

Is there a better way to establish global constants in VS web projects?
 
John Ruiz said:
If your classes aren't extending System.Web.HttpContext in some way, they're
not going to have access. You'll notice that your aspx pages extend
System.Web.UI.Page. Page has an HttpContext, which means that your
codebehind classes have access. on the other hand, classes that you add
yourself won't have automagic access.

Thanks for the explanation. Now I know a little more!
 
Back
Top