*Experts* Bucky Posted November 6, 2002 *Experts* Posted November 6, 2002 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? Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
*Experts* Bucky Posted November 13, 2002 Author *Experts* Posted November 13, 2002 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. :) Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
*Gurus* Derek Stone Posted November 13, 2002 *Gurus* Posted November 13, 2002 Just to make note of it, you can access Application and Session data from a code-behind. Page.Application.Session("someVariable") = "someData" Quote Posting Guidelines
*Experts* Bucky Posted November 17, 2002 Author *Experts* Posted November 17, 2002 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? Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
*Gurus* Derek Stone Posted November 17, 2002 *Gurus* Posted November 17, 2002 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. Quote Posting Guidelines
*Gurus* divil Posted November 17, 2002 *Gurus* Posted November 17, 2002 Correct. [edit]Bah, I was beaten to it.[/edit] Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.