I'm sure I probably need to change my thinking a bit on how I structure these ASP.NET applications, but is there a place I can put code that can be called from all of my web forms? Is there a good place to look at examples of good ASP.NET code structure, etc?I usually create a "globals" class and define these methods as static (C#) or shared (vb) in the class. So you end up writing stuff like:
lblSigma = globals.CalcSigma(dblFci)
One way to do it is to implement a BasePage class that all you webforms could derive from.
Check this article out:
aspalliance
So, just to clarify (I'm really new), I should create a VB.NET class library project with my functions in it and build it into a DLL.
Once that is done, what steps do I need to go through to make my ASP.NET project recognize it?
Thanks again!
If you use the BasePage approach you can build a class library and then add that assembly as a reference in you main project.
If you use the global.asax approach with shared functions you don't have to create a separate project. The codebehind for global.asax.vb is compiled into your mainproject assembly.
I would just add a new class to your existing project. No need to create a new project.
Jim, I guess I'm not familar enough with vs.net to know how to do that. What do I "click" to add a class to my existing project?
Thanks again to everyone for the info.
Right-click on the project itself in project-explorer. Choose "Add" then "Add Class".
I keep all of my code like this, including DAL, BLL, etc. in a "Code" directory within the project, but you can put it anywhere.
0 comments:
Post a Comment