OK, this is not as easy to accomplish, however you said you have some general database function in the main page. First question is does this code appear on every page (or at least would it be beneficial to have on every page)? If so you create your own class that inherits the Page class. You can then reference the function in a user control like the code below (it is possible to reference the main page class, but it is trickier in ASP.Net 2 due to the way the namespaces are created):
C# Code
Code:
MyPageClass myPage = (MyPageClass)this.Page;
myPage.TheDbFunction();
I'm actually thinking that this Database Generic Function should probably be implemented in a static/shared class which simply means you put a file in the App_Code folder, and would look like:
C# .Net v2 Code (static / shared classes not available in v1).
Code:
public static class MyDbRoutines
{
public static void MyGenericFunction()
{
//code for generic function
}
}
C# .Net v1 Code
Code:
public class MyDbRoutines
{
///<summary>
/// Private constructor so class cannot be instantiated
///</summary>
private MyDbRoutines()
{}
public static void MyGenericFunction()
{
//code for generic function
}
}
Of course, this should explain what you need to do for a generic 'Utility' class. As your code gets bigger you could look at putting this code into a seperate assembly which can then be referenced in the web application and allow you to have multiple websites using the same code-base. As an example of this I have a common library that I include with all projects, this library provides several functions that I commonly using, for example a routine to CheckFilenames for invalid characters. As you develop more and more code you would start to create multiple libraries (I have been using .Net since early alpha and now have several assemblies I link in depending on functionality I need).
Bookmarks