Visual Studio 2005 + ASP.NET + Modules? =D

I need some way that I can access a function across all of the pages within my site. The problem is that there seems to be no support for Modules. I'd use a class, but I don't want to create an object each time. I just need to call a function. Any ideas



Answer this question

Visual Studio 2005 + ASP.NET + Modules? =D

  • Anmol Ranka

     Speedbird186 wrote:
    The difference between LosDude's solution and Rainier's solution is that Rainier's solution will enable you to call the static (Shared in Visual Basic) methods in the class from any portion of the code. LosDude's solution would only enable you to call the code from a class that inherits from your base page. (Unless you would make the method in the base page class still static/Shared, but that would be a poor OO design.)

    If you add a class in your App_Code folder with only static/Shared methods, it's best to mark it abstract (MustInherit in Visual Basic) and add a protected default constructor.

    HTH,

    SA.


    ah! Got it, thanks!

  • pu132

    The difference between LosDude's solution and Rainier's solution is that Rainier's solution will enable you to call the static (Shared in Visual Basic) methods in the class from any portion of the code. LosDude's solution would only enable you to call the code from a class that inherits from your base page. (Unless you would make the method in the base page class still static/Shared, but that would be a poor OO design.)

    If you add a class in your App_Code folder with only static/Shared methods, it's best to mark it abstract (MustInherit in Visual Basic) and add a protected default constructor.

    HTH,

    SA.

  • aimeeoco

    You have many options here.  I like to create a base class for my pages because I add much functionality to my site that .NET doesn't include int the Page class.  Then, for each page, instead of inheriting from Page, you would inherit from that base class.

    That's probably the best way in my opinion.   


  • Mark Goldstein

    But that's not what he's asking. If the code is strictly for PAGE functionality as he indicates, then it should be based in a BASE CLASS inherited by the pages. Otherwise it is poor OO design to just toss everything into static (shared) calls. That level of abstraction is improperly implemented.

    If it is for the pages, base it in a base PAGE class.


  • anomolous

    Again, improper design. True, it will work, but it's not proper OO design. Sorry.
  • Sarah71

    Just implement the functions you need as Shared/Static class members if you don't want to create an instance to be able to call them.

  • Visual Studio 2005 + ASP.NET + Modules? =D