Using my own Class in ASP.NET without an editor

Rolandatem

Newcomer
Joined
Jun 7, 2005
Messages
1
Hi guys, Im really new to ASP.NET, although i've been using classic ASP for years.

Before I continue with my question, I wanted to make sure that whoever tries to answer my question know that I am not using VS.NET or any editor of that type. I'm strictly using notepad, IIS, and the .NET framework

Ok, well...

I've noticed that in ASP.NET you can seperate the design from the code with .aspx and codebehind files. This is really nice and convenient, however it seems (unless im wrong) there is one codebehind file for each .aspx file. I'm sure that you can use the same codebehind file for another .aspx file, but thats not my problem. What if I want to have a subroutine/function that I will use multiple times throughout the website?

In this case, I figured i'd make a class file and use that throughout the page. This is where i'm having errors. I've even found out how to compile my class, but I still havent found out how to get the codebehind files and the class to work together ;_;

The following is sample code of my problem:

--------- default.aspx ---------
Code:
<%@ Page Language="vb" AutoEventWireUp="false" src="Default.aspx.vb" Inherits="DefaultForm" %>

<html>
	<head>
		<title>Test</title>
	</head>

<body>
<form runat="server">

<asp:label id="lblMessage" runat="server" text="empty" /><br />
<asp:textbox id="txtName" runat="server" /><br />
<asp:button id="btnShowMyName" runat="server" text="Show My Name!" onclick="ShowMyName" />

</form>
</body>

</html>

---------- default.aspx.vb [codebehind] ----------
Code:
Public Class DefaultForm
	Inherits System.Web.UI.Page
	Protected WithEvents txtName As System.Web.UI.WebControls.Textbox
	Protected WithEvents lblMessage As System.Web.UI.WebControls.Label
	
	Public Sub ShowMyName(sender As Object, e As System.EventArgs)
		Dim TestClassObject As New TestClass '--[B] error here[/B]
		
		lblMessage.Text = TestClassObject.GetMessage(txtName.Text)
		
		TextClassObject = Nothing
	End Sub
End Class

-------- TestClass.vb -----------
Code:
Public Class TestClass
	Public Function GetMessage(TheName As String) As String
		GetMessage = "Hello " & TheName & "!"
	End Function
End Class

In classic ASP, I could create my .DLL file, but I had to register it. From what I understand, you dont have to in ASP.NET, is this true?

The following is the command line compile syntax I use (i'm not using the /r because I dont need one in this case:

(vbc location)\vbc testclass.vb /out:testclass.dll /target:library /verbose

When I run that, it states that I have compiled the class successfully.

Am I suppossed to place this .DLL file anywhere specific? May that be the problem?

The main point of this thread is: How can I create my own classes and use them throughout a website?
 
Back
Top