application variable in pure code file?

J

josh harmon

I've got the following simple line of code in a codefile in an asp.net
application. The codefile has a lot of common routines I use in several
applications. When I try to use a application variable it throws, "Object
reference not set to an instance of an object" errors. Can you not use
application variables in codefiles that aren't related to a page? I still
have the class set to inherit System.Web.UI.Page.... For what it's worth,
here's the code that's throwing the error:


Application("tmLastErr") = DateTime.Now

This works fine when set in a code behind file for a page (default.aspx.vb
for example) but not in common_code.vb.

Josh Harmon
J.Harmon[remove_to_email]@tcu.edu
 
S

Scott Allen

Hi Josh:

Don't derive from the Page class unless you really have a Page that
will created and initialized by the ASP.NET runtime.

As long as you are in the midst of processing a request, you can reach
the Application object via HttpContext.Current.Application.
 
J

josh harmon

Scott:
How right you are. I guess I should have been able to figure that much out
myself. But I couldn't and you did. Thanks a lot. That's a huge help.

Josh

Scott Allen said:
Hi Josh:

Don't derive from the Page class unless you really have a Page that
will created and initialized by the ASP.NET runtime.

As long as you are in the midst of processing a request, you can reach
the Application object via HttpContext.Current.Application.

--
Scott
http://www.OdeToCode.com/blogs/scott/

I've got the following simple line of code in a codefile in an asp.net
application. The codefile has a lot of common routines I use in several
applications. When I try to use a application variable it throws, "Object
reference not set to an instance of an object" errors. Can you not use
application variables in codefiles that aren't related to a page? I still
have the class set to inherit System.Web.UI.Page.... For what it's worth,
here's the code that's throwing the error:


Application("tmLastErr") = DateTime.Now

This works fine when set in a code behind file for a page (default.aspx.vb
for example) but not in common_code.vb.

Josh Harmon
J.Harmon[remove_to_email]@tcu.edu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top