Last post Jun 24, 2010 02:27 PM by skamin
Jan 31, 2008 11:44 PM|taowang|LINK
I use VS2008 to create a Asp.net web application. Then I create a App_Code new folder. After that I add a new item, Class1.cs, under App_Code.
When I come back to default.aspx.cs and type Class1 within Page_Load, I found it is not recognized. If I compile, compiler error says "Class1" could not be found.
Feb 01, 2008 12:05 AM|Jeev|LINK
If you are using the "web application project" instead of "web site", then the code does not get dynamically compiled. You would be better off adding these classes a class library project and adding the reference to your web application project
However if you are using website , the class in the App_code will get compiled dynamically
Feb 01, 2008 12:07 AM|dinesh_sp|LINK
Hi Tao, Have you made it public and secondly have you added some properties or methods to it???
Feb 01, 2008 04:23 AM|taowang|LINK
I did use "web application project". You answer explains.
I tried this. Add new Class.cs. Build project. Then reference Class1 from default.aspx.cs. It still deosn't work. This leads to another question then. Does this mean, in "web application project", I'm not able to add a new Class file to define new classes?
Class1 is public with no property.
Feb 04, 2008 05:10 AM|Vince Xu - MSFT|LINK
Did you used in VS2005? If so, there are several suggestions.
1. You can put the new class file into any folder EXCEPT App_Code folder. It means that you can't directly access the class in the App_Code folder and you can put the class file in other folders.
2. For example, the new class file "Class1" in the folder "ppp".
public class Class1
You can call the "Class1" with WebApplication1.ppp.Class1 in the default.aspx.cs
But in VS2008, this issue has been resolved and every thing is ok.
Hope it helps.
Apr 25, 2008 12:13 PM|gyan_flip|LINK
Apr 25, 2008 12:15 PM|gyan_flip|LINK
I am using .Net3.5 and Asp.Net2008. I have created a web application and added a folder "App_Code" and a class file in "App_Code" folder. But I am not able to get the reference/intellisence for the class in any WebForm.aspx.cs file. Do anyone help?
Apr 29, 2008 09:38 AM|gyan_flip|LINK
Reply From Scott:
[" Hi Gyan,
If you use a "web application" project you'll want to add the class outside of the \app_code directory. When you do this it will be compiled with the rest of your application and you'll have intellisense against it.
If you use a "web site" project you can pull the class in \app_code and get intellisense.
Hope this helps,
This means that we cannot add \app_code and class files in \app_code folder when we are using "web application", only we can add \app_code folder in "web site".
May 16, 2010 04:58 PM|dabhi_mayur|LINK
In Visual Studio Professional 2008, you can still create the
App_Code folder by right-clicking on the Web Project and selecting
Add, then Add Folder. Rename the new folder to App_Code.
Contrary to some recommendations on the Web that you should not use the App_Code folder because you cannot place common Web UI codes or classes in this folder, you can do so by setting
Build Action of each class to
Compile. Suppose this step is not done, the classes defined in this folder will not be visible to your other codes. This explains why people recommended against the use of App_Code folder in VS 2008.
Suppose you have a class called WebCommon.cs in this folder. All you have to do is to right-click on this file and select
Properties. A properties window will appear. Set
Build Action to
Compile. Viola! The class can be accessed exactly like what you have seen in VS 2005.
Jun 24, 2010 02:27 PM|skamin|LINK
Thanks dabhi ... this is a real solution to an annoying anomaly between web app projects and website projects .. good man.