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

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
 
W

_Who

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
 
W

_Who

The Error from "Session" was because of the use of "Shared"
Guess all subs in App_Code are implicitly Shared.
 
W

_Who

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.
 

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,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top