Module scope

Bucky

Contributor
Joined
Dec 23, 2001
Messages
791
Location
East Coast
I have a bunch of functions that I want to use throughout my
ASP.NET project, and I want to put them in a module so the
entire project can use them.

This works fine with the code-behind pages, but if I want to call
one of these methods in the ASPX page itself (eg: <%
=GetNavBar() %>), the module is not in scope. The module and
the functions are both declared as Public.

Right now I have to put the methods in a class and declare a new
Public instance of the class in the code-behind page, which I can
then access from the ASPX code. This is a problem, however,
because I cannot access the Session variables directly, and a
new declaration of the class has to be put in every page.

Is there any way to declare the methods publicly so the ASPX
page can use them?
 
After reading divil's responses about evil modules in this thread, I
tried placing the methods in a class, declaring them as Public Shared.
Sure enough, when calling them from the page by using
<% =ProjectName.ClassName.MethodName() %>, everything
worked perfectly.

Thanks divil. :)
 
Yes, but since the class is declared in its own .vb file, I cannot
access Session variables without passing the Application or
Session class to the method.

Correct?
 
Well, a page's code-behind is its own file and it can access Application and Session variables. A class that isn't specified as the page's code-behind won't be able to access those collections however.
 
Back
Top