Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 10th, 2007, 11:26 AM
Authorized User
 
Join Date: Sep 2006
Location: Lenexa, KS, USA.
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default Classes in App_Code "not defined"!?

Hi all,

I've done several VB.Net/ASP.Net 2003 projects, and I did 98% of a VS2005/ASP 2.0 project that a co-worker initially laid out a few screens for. However, now I’m doing a new VS2005/ASP 2.0 project, and have a stupid error. I’ve found a fair number of people asking about this on various forums, but no resolutions, and would be pathetically grateful for any help.

In a nutshell: in my aspx.vb code, when I reference my classes in the App_Code folder, they’re “not defined”.

<Here’sWhatIDid>

1. I clicked File / New Project, and selected “ASP.Net Web Application”.
2. I right-clicked on the level below the Solution level in Solution Explorer – is this still called the Project level?, clicked Add New Item, and added a Web Form.
3. I pasted some HTML in from a similar project.
4. I right-clicked from the Designer View, clicked View Code, and pasted some VB code in, directly from the similar project (as a starting point).

That VB code has “Dim MyXXX As New clsXXX”, which of course gives a message “Type clsXXX is not defined”. So,
1. I click on the Project, click “Add”, click “New Folder”, and name it App_Code.
2. I then right-click on this folder, click “Add”, click “Class”, and name it clsXXX.
3. I open that new file and paste the code in from the similar project’s class file. It’s a Public Class clsXXX.
4. It doesn’t work when I “add existing item” and specify the similar older project’s class file, either.
5. The same thing is happening for my DatabaseFunctions class in DatabaseFunctions.vb in App_Code.

<Here’sWhatIDid />

The class is still “not defined” in my aspx.vb code, even after I rebuild everything. Even if I drag the clsXXX.vb file up to the Project level, it’s still “not defined”.
For my DatabaseFunctions class, I also tried putting a Namespace designation in the DatabaseFunctions.vb file and “Imports” the namespace in my aspx.vb.

Does anybody know how to fix this? Thanks!!!!!!



Reply With Quote
  #2 (permalink)  
Old December 10th, 2007, 11:36 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You can't use an arbitary folder named 'App_Code'. The step where you clicked Add, New Folder should instead be: 'Add ASP.NET Folder' select 'App_Code' from that and place your class files in there.

Alternatively, if you do Add --> Class Visual Studio will prompt you about the non-existance of the App Code directory and offer to create it for you.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
Reply With Quote
  #3 (permalink)  
Old December 10th, 2007, 11:47 AM
Authorized User
 
Join Date: Sep 2006
Location: Lenexa, KS, USA.
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Dparsons,

Thanks for your quick answer! However... :(

1. When I right-click on the project, click Add, click "Add ASP.Net Folder", I was definitely expecting to see "App_Code" as an option, but the only options to choose are: App_GlobalResources, App_LocalResources, App_Data, App_Browsers, and Theme.

2. When I right-click on the project, click Add, click "Class", it brings up the Add New Item dialog, with "Class" hilited under the "Visual Studio Installed Templates" section, and the class name defaulting to "Class1.vb". When I click OK, it doesn't prompt me to create App_Code, doesn't create it on its own, and puts the class at the level right under the project.

Thanks... LenexaKS


Reply With Quote
  #4 (permalink)  
Old December 10th, 2007, 11:54 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Did you remove your folder named App_Code?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
Reply With Quote
  #5 (permalink)  
Old December 10th, 2007, 12:07 PM
Authorized User
 
Join Date: Sep 2006
Location: Lenexa, KS, USA.
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had renamed it. Just to be sure, I just now deleted App_CodeX folder, deleted the clsXXX file that VS added under the project, saved, rebuilt, exited VS, got back in, and...
1. "Add ASP.Net Folder" still doesn't show "App_Code" as an option.
2. Right-clicking on the project, click Add, click Class, and click OK to add Class1.vb still adds it just under the project level; it doesn't prompt me to add an App_Code folder.

When I click on About Visual Studio, the VS / VB oriented things are:
Microsoft Visual Studio 2005
Version 8.0.50727.762 (SP.050727-7600)
Microsoft .NET Framework
Version 2.0.50727

Installed Edition: Professional

Microsoft Visual Basic 2005 77626-009-0000007-41159
Microsoft Visual Basic 2005

Microsoft Visual Studio 2005 Professional Edition - ENU Service Pack 1 (KB926601)
This service pack is for Microsoft Visual Studio 2005 Professional Edition - ENU.
If you later install a more recent service pack, this service pack will be uninstalled automatically.
For more information, visit http://support.microsoft.com/kb/926601

Thanks again!

Reply With Quote
  #6 (permalink)  
Old December 10th, 2007, 12:15 PM
Imar's Avatar
Wrox Author
Points: 67,317, Level: 100
Points: 67,317, Level: 100 Points: 67,317, Level: 100 Points: 67,317, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,230
Thanks: 66
Thanked 1,416 Times in 1,396 Posts
Default

File | New Project | ASP.NET Web Application leads to a Web Application Project that doesn't use the App_Code folder.

You can place classes anywhere provided they are of the same type as the parent project (e.g. .cs files in a C# project)

For more info: http://webproject.scottgu.com/

For a Web Site Project, choose File | New Web Site instead. This project type uses the App_Code folder.

Imar



---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Reply With Quote
  #7 (permalink)  
Old December 10th, 2007, 12:22 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

These settings almost match mine. I have SP1 for the .NET Framework installed so my VB version differs slightly: xxx-41990

In any event, I just created a new website in VS 2005 and my Solution Tree looks like this:
----Solution
------Project
---------App_Data
---------Default.aspx

If i right click on my project and select Add ASP.NET Folder my options are:
bin
App_Code
App_GlobalResources
App_LocalResources
App_WebReferences
App_Browsers
Theme

If i right click on my project and select 'Add New Item' and select 'Class' VS pops up the message: You are attempting to add a class to an ASP.NET Application. For a class to be generally consumable in your site, it should be placed inside the 'App_Code' folder. would you like to place the class in the 'App_Code' Folder.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
Reply With Quote
  #8 (permalink)  
Old December 10th, 2007, 01:23 PM
Authorized User
 
Join Date: Sep 2006
Location: Lenexa, KS, USA.
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks guys! I'll make it a new "web site" instead of a new "web app project" - that's behaving as you described. (I had just been copying how the older project, the one I was copying some code from, was set up.) What a relief - thanks again.

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ADODB.Connection user-defined type not defined Wall st Guru Excel VBA 2 March 26th, 2014 03:44 PM
access app_code classes pooh2006 ASP.NET 2.0 Professional 1 April 5th, 2006 09:21 AM
Appl-defined or Object-defined error 1004 chp Excel VBA 3 April 4th, 2006 08:12 AM
User-defined type not defined (Icecream.mdb) dloren01 BOOK: Beginning Access VBA 0 June 22nd, 2005 10:36 PM
Application-defined or object-defined error James Excel VBA 1 August 12th, 2003 11:50 PM



All times are GMT -4. The time now is 11:16 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.