Can context file reference a sub that's iin the .master or is there such a thing as a module

  • Thread starter Thread starter _Who
  • Start date Start date
W

_Who

I have a sub that I need to use in the .master and the context aspx.vb
files.

How can I do that without reproducing it in each of those files.

Can I reference it if it is in the .master or is there such a thing as a
module?

I can't find any documentation on how to do this.

Thanks
 
Even though I mentioned master in my post, I was focused on looking for a
module-like approach.

I found out about App_Code and created a class file in it containing the
sub.

I had just noticed that a reference to Session in the sub code produced an
error when I received your post.

I changed to the method you pointed to (using master.mysub) and that works
well.

For future reference: Do you know why I received an error when the sub
referenced Session (Session is not declared)?

If I got rid of that error do you think that approach would have worked?

A related question - there is any reason asp.net not to use Shared if a sub
does not access an instance variable?



Thanks a lot
 
The Error from "Session" was because of the use of "Shared"
Guess all subs in App_Code are implicitly Shared.
 
Mark Rae said:
[please don't top-post]
For future reference: Do you know why I received an error when the sub
referenced Session (Session is not declared)?

Session needs a current HttpContext - HttpContext.Current.Session["....."]

Thanks, I made a note in the code for next time.
 
Back
Top