Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 4th, 2004, 05:25 PM
Registered User
 
Join Date: Apr 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using a class without compiling it

Hello

I am trying to develop a class, which I will only use within my ASP.NET site. I therefore created a class and inserted a simple test method in it. However, when I try to use this class within my ASP.NET page, I am told that "Type 'Class1' is not defined", I cannot seem to find out how I can use this class, that exists within the same project as my ASP.NET site.

[u]The class' code is:</u>
Namespace Test
    Public Class Class1
        Public Shared sTitle As String = "hallo"
    End Class
End Namespace

[u]The page's code is:</u>
<%@ Page Language="vb" Codebehind="main.aspx.vb" %>
<%@ Import Namespace="PaulSite.test" %>
<script language="VB" runat="server">
    Public Sub Page_Load(sender As Object, E As EventArgs)
        Dim Data as Class1 = new Class1()
    End Sub
</script>
<html>
  <head><title>main</title></head>
  <body></body>
</html>

I have checked the project properties in VS and it says the root namespace is "PaulSite"

Is there anyway to use this class without compiling it?

Thanks in advance

Paul

 
Old April 5th, 2004, 01:47 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Is the class defined in the ASPX that is using it?

If it is not, but located in a separate .vb file, you'll need to compile it to a DLL using the VBC compiler. If you're using Visual Studio .NET, you can have your entire application compiled into a single DLL.

If it is located in the same ASPX page that is using it, I don't see a reason why it wouldn't work. Can you post the (relevant) code for that page?

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old April 5th, 2004, 04:56 AM
Registered User
 
Join Date: Apr 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

The class' code is in a seperate .vb file, but within the same VS project. I was hoping that because they were in the same project I could use/reference the class in the .vb file from my .aspx file. Is this not possible?

The page's code and the class' code are included in the original posting and they are in seperate files (the page is in an .aspx file and the class is in a seperate .vb file)

Thanks for your input

PD

 
Old April 5th, 2004, 05:55 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

If they are both in the same namespace, it should work.

Did you compile the VS project? The subject of this thread says "without compiling", but you'll have to compile the code in separate VB classes before you can use it. Only inline code in ASPX files will be compiled at run-time.

Do you have a problem getting it to work at run-time or at design-time? And why aren't you using the Code Behind feature of VS.NET? Can you "see" Class1 in the Code Behind of main.apsx?

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old April 5th, 2004, 09:57 AM
Registered User
 
Join Date: Apr 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

They are both in the same namespace.

When I said "Using a class without compiling it" I wanted to communicate that I didn't want to have to create a DLL using vbc.exe while I was still developing the site and developing this class.

I didn't compile the project, but I thought that it would compile the class if it needed it.

I am creating this class in a seperate file because I want to use it throughout my site. I was not using the code-behind class as I thought that posting the .aspx page would be simpler and it causes the same error in the code-behind class or when I embed the code in a script block in the .aspx.

I can see the class (it is present in intellisense) in the code-behind of main.aspx, but when the code that references the class runs from the code-behind it still creates the same error message.

Paul

 
Old April 5th, 2004, 10:23 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Right, I see.

I think you have at least three options:

1. Define the class inline in the aspx page. This way, it will be compiled at run-time so it can be used. Not very useful, because you can't reuse the class.

2. Use a separate VB file and compile the class in a separate DLL using the VBC compiler. You can accomplish the same thing by adding a Class Library project to the VS.NET solution. Useful, because it allows you to separate Business Logic defined in class from presentation stuff defined in ASPX pages and their code behind.

3. Use the Code Behind feature of VS.NET the way it is supposed to be used. If you create a page in VS.NET, the default model is to use Code Behind. This means that any in-line code is *not* compiled when you request the page. However, if you choose Preview in Browser, VS.NET will recompile the application (including separate classes) when changes have been made. This may take a few seconds, but it guarantees you are always looking at the latest version of your application.

Does this help? If not, please let me know.

Cheers,

Imar

---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old April 5th, 2004, 12:42 PM
Registered User
 
Join Date: Apr 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

As you suggested the first option doesn't really work for me, but I will try options 2 and 3 tonight as soon as I get home

Thanks very much for your input and patience!

PD

 
Old April 5th, 2004, 02:42 PM
Registered User
 
Join Date: Apr 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My goodness, you are a genius, a genius walking among men.

I compiled the entire solution and it worked, so then I added it to a seperate project within the same solution and compiled it all and it works, all I have to do is change the class, recompile that project (which is now seperate from the actual website itself) and the changes are propogated to my site. All of it is within VS, no vbc.exe annoyance, absolutely marvellous.

Thank you very much from a grateful Paul

 
Old April 5th, 2004, 02:51 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Well, I am not the genius, the guys over at Microsoft who invented this are the geniuses. I just followed their instructions.... ;)

Glad it works fine now....

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Property access from Class within Partial Class zoltac007 C# 2005 0 December 1st, 2006 01:01 AM
compiling class sarah lee ASP.NET 1.0 and 1.1 Basics 3 September 14th, 2006 10:49 AM
Regarding Class Library (.dll) from class file manish.sharma04 BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 1 March 3rd, 2006 07:32 AM
Errors when Compiling a Class File Jim3 General .NET 1 March 16th, 2005 01:57 AM
How to include c# class and vb class in the .vbprj umeshayk VS.NET 2002/2003 2 January 9th, 2004 12:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.