How do I use my own referenced classes in an asp.net page?

B

Bodza Bodza

I have added several classes to an ASP.net project via the PROJECT>ADD
CLASS menu.

When I try to use them in the main page it fails with a type not found
error.
What gives? Can't you access code in classes which you have added to
the project?

Here's the code:


<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="TranslatorSearchScreen.aspx.vb"
Inherits="TranslatorSearch.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>
<head>
<title>Translator Search Screen</title>
</head>
<body MS_POSITIONING="GridLayout">

<h1> Translator Search Screen </h1>
<%
dim strAction as string
strAction = request.form("Action")
select case strAction
case "Search"
dim x as clsZ
end select

%>

<form id="Form1" method="post" runat="server">

<input type = "submit" value = "Search" id=btnSearchname =
"Action">

</form>
</body>
</html>



-----------------------


Public Class MainPage
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "
#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

End Sub



End Class

Public Class clsZ

End Class
 
K

Kevin Spencer

In order to use a class you developed in another class, you have to:

1. Add the Project to your solution (as you already have)
2. Add a Reference to the project in the class's References
3. (Optional) Add an Imports Statement to your code (unless you want to
reference the whole namespace hierarchy when using the class)

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
R

Raterus

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="TranslatorSearchScreen.aspx.vb"
Inherits="TranslatorSearch.WebForm1" %>

Do you have a class "WebForm1" defined, because that is what its trying to
find with this line. In this example you probably just need to replace
TranslatorSearch.WebForm1 with TranslatorSearch.MainPage.

And what is this!

<%
dim strAction as string
strAction = request.form("Action")
select case strAction
case "Search"
dim x as clsZ
end select

%>

no no! :)

--Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top