Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 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 June 2nd, 2005, 02:48 PM
Authorized User
 
Join Date: Mar 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using a Class without an editor

Hi guys and gals, I'm pretty new to ASP.NET, although Im pretty proficient in Classic ASP.

I am building some pages to help myself learn ASP.NET and have come across something. I like the idea of the code-behind file, as it makes the code much cleaner. However, I noticed that each aspx file has its own code-behind. So, I decided to create a general class file to place all my routines that I want to use throughout the website. That is where my problem is...

Using VS.NET I can use a class by just creating, or including an existing class file easily.

My question is tho, is there a way to include the class file, if you're not using an editor like VS? I like to code my websites straight text, but when I do this I am constantly getting the following error:

BC30002: Type 'MyOwnClass' is not defined

And it points to the line this line of code:
Dim MyOwnClassObject As MyOwnClass

Adding 'New' to the text above also did not work.

Think someone can explain how I can create my own class files and be able to use them throughout my website without the use of an editor? I'm afraid it may be something really simple like a declaration that I dont know about ;p

 
Old June 2nd, 2005, 03:17 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

It has nothing to do with the editor but the fact that the editor that works (VS) is compiling the classes to an assembly. You can do this with any editor. You just need to compile the code files.

I'd suggest creating a batch file that calls the .NET compiler to create your assembly file in the bin folder underneath your web application root. You'll need to run the build after any code file changes. The one exception to this is if you use code-behind files referenced by the @ Page directive's "Src" attribute. Using this results in dynamic compiling of the code file when the page is requested. However, for any code to access classes that are not part of a page's inline or referenced code-behind code you'll need to compile.

-Peter
 
Old June 3rd, 2005, 10:04 AM
Authorized User
 
Join Date: Mar 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks alot Peter, I do use code behind files using the src when calling, so if I'm understanding correctly, I dont need to compile those. Only the classes behind that are never really called, just declared?

Another question tho, like I've said, I am coding this test site in straight text with no editor (unless you wanna call notepad an editor ;p ). After I compile my class file, does it have to reside in a specific place? Im worried about the future where I would develop on my home computer and then upload to a hosting company. I want to make sure it would still work.

Thanks again

 
Old June 3rd, 2005, 12:41 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Code files that are referenced by the Src attribute are dynamically compiled on the page request. Once they are compiled they are available for use by any code running in the appdomain of the web application. In the case of an ASPX page, the code and markup in the ASPX file is dynamically generated into a code file containing a class and then compiled. It just happens that the generated class contains an Inherits statement driven by the Inherits attribute in the page directive. The class that is inherited is found in the dynamically compiled assembly created by the file referenced in Src.

The application can live anywhere as long as it's in a web application under IIS (server root or virtual directory). Any assemblies need to be in the bin directory or the working directories of .NET. You can compile on one machine and xcopy deploy to another without a problem.

-Peter
 
Old June 6th, 2005, 09:52 AM
Authorized User
 
Join Date: Mar 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, im sorry to bug again. I guess I'm misunderstanding something (also I cant find the appropriate manual compiling commands) ;_;

This is an example of what I have

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

[html items with a button]
-----------------

--default.aspx.vb--
Public Class DefaultForm
    Inherits System.Web.UI.Page
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Public Sub Button1_Click(sender As Object, e As System.EventArgs)
     Dim MyClassObject As New MyClass <- error here
     MyClassObject.RunThisCode()
     MyClassObject = Nothing
End Sub
End Class
--------------------------

--MyClass.vb--
Public Class MyClass
Public Sub RunThisCode()
     'do something
End Sub
End Class
---------------------

As you can see, I can get the .aspx and .aspx.vb files to work properly, its when I want to use the third file (MyClass.vb), is where I get the problem. I tried adding another page directive, but I got an error stating that I could only have one. Think you can show me the syntax of how I can use the MyClass.vb items using the example above? And if its not too much trouble, the correct compiling syntax for the class?

Thanks abunch, sorry for not understanding completely ;p
 
Old June 7th, 2005, 06:00 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The VB compiler is located in the framework directory, for version 1.1 it's usually something like this:

C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322
If you will programming in this model regularly, I'd recommend adding that path to your PATH system environmental variable. Then you can just type in "vbc" for the VB compiler. Just type that and you'll see all the switches and options available. Then you can compile your third file into an assembly that will then be visible by the running ASPX page.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using logging class as a static class punitw General .NET 0 August 14th, 2008 03:03 AM
Property access from Class within Partial Class zoltac007 C# 2005 0 December 1st, 2006 01:01 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
Class disappears in the class panel hint2310 Visual C++ 0 September 18th, 2004 03:46 PM
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.