views:

59

answers:

1

Hi,

I'm writing an internal program using ASP.NET (Visual Studio 2008). The basic premise is that folks will connect to the page through their web browser, put in some data (which will be validated and sanitized of course), click "submit" and then a query will be run on a database. I told you that story so I can tell you this story - I want to make my program modular for the likelihood that this program will be updated later on, and probably extended. My initial thought is to compile the database handler as a dll and then use its functionality on my page (see my little diagram). But I can't figure out how to hook the dll into my page - My Google-fu has failed which leads me to my questions:

1) Is creating a dll the "right" solution? If so, continue to question 2, if not, what should I be doing? Any resources/tutorial links would be appreciated.

2) How do I attach a dll? Visual Studio tells me I can't Imports from an .aspx page, and I've tried <%@ Import namespace="MyDllName" %> and a few other variations, none of which worked.

Thanks!

alt text

EDIT (Solved):

I had tried (more or less) what Joel posted, but was going about it the wrong way. Thanks to the vote of confidence and a nudge in the right direction, here's what I did:

Right-click on "Solution" in the solution explorer > add > new project

Select Visual Basic > Windows > Class Library, put in my class name, click OK

Add a new Sub to the class, then build the class

Right click on the web project > add reference

Add the dll the class library build created

In the .aspx file before the tag, put the following code:

<script runat="server">
Dim somevar As New Mydllname.MyClassName()
Sub MyPageLoad(ByVal sender as Object, ByVal e As EventArgs) Handles MyBase.Load
    somevar.someSub()
End Sub
</script>

Compile and run

It works! (at least it did for me)

+1  A: 

What you want to do is add a separate class library project to your solution. Looking at n-tier design, this class library project will be your data layer. Your asp.net project will be able to use classes that you build in the data layer project.

Joel Coehoorn